Search
 
SCRIPT & CODE EXAMPLE
 

CPP

deque c++

/*  A deque is a dynamic array whose size can be efficiently 
changed at both ends of the array. Like a vector, a deque provides
the functions push_back and pop_back, but it also includes the 
functions push_front and pop_front. */
deque<int> d;
d.push_back(5); // [5]
d.push_back(2); // [5,2]
d.push_front(3); // [3,5,2]
d.pop_back(); // [3,5]
d.pop_front(); // [5]
Comment

dequeue c++

// g++ std-deque.cpp -o a.out -std=c++11
#include <iostream>
#include <deque>

using namespace std;

int main() {
    deque<int> d = {1, 2, 3, 4};  // [1, 2, 3, 4]

    d.push_back(5); // [1, 2, 3, 4, 5]
    d.pop_front(); // [2, 3, 4, 5]
    d.push_front(0); // [0, 2, 3, 4, 5]
    d.pop_back(); // [0, 2, 3, 4]

    // 印出 deque 內所有內容, c++11 才支援
    for (int &i : d) {
        cout << i << " ";
    }
    cout << "
";

    cout << d[0] << " " << d[1] << " " << d[2] << "
";

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: set iterator 
Cpp :: flutter single instance app 
Cpp :: glfw error: the glfw library is not initialized 
Cpp :: vector::at() || Finding element with given position using vector in C++ 
Cpp :: string concatenation operator overloading c++ 
Cpp :: potato 
Cpp :: ImGui button wit picture 
Cpp :: nullptr c++ 
Cpp :: cout stack in c++ 
Cpp :: modular exponentiation algorithm c++ 
Cpp :: move assignment operator c++ 
Cpp :: error uploading arduino code 
Cpp :: clear map in C++ 
Cpp :: c++ map 
Cpp :: c++ class methods 
Cpp :: new in c++ 
Cpp :: copy vector c++ 
Cpp :: abs c++ 
Cpp :: c++ unordered_map initialize new value 
Cpp :: file streams in c++ 
Cpp :: c++ segmentation fault 
Cpp :: C/C++ loop for 
Cpp :: print numbers after decimal point c++ 
Cpp :: end vs cend in cpp 
Cpp :: use textchanged qt cpp 
Cpp :: c++ camera capture 
Cpp :: c++ bind port 
Cpp :: opengl draw cresent moon c++ 
Cpp :: c++ constructor inheritance 
Cpp :: what do I return in int main() function c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =