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

how to use deque in c++

// CPP Program to implement Deque in STL
#include <deque>
#include <iostream>
  
using namespace std;
  
void showdq(deque<int> g)
{
    deque<int>::iterator it;
    for (it = g.begin(); it != g.end(); ++it)
        cout << '	' << *it;
    cout << '
';
}
  
int main()
{
    deque<int> gquiz;
    gquiz.push_back(10);
    gquiz.push_front(20);
    gquiz.push_back(30);
    gquiz.push_front(15);
    cout << "The deque gquiz is : ";
    showdq(gquiz);
  
    cout << "
gquiz.size() : " << gquiz.size();
    cout << "
gquiz.max_size() : " << gquiz.max_size();
  
    cout << "
gquiz.at(2) : " << gquiz.at(2);
    cout << "
gquiz.front() : " << gquiz.front();
    cout << "
gquiz.back() : " << gquiz.back();
  
    cout << "
gquiz.pop_front() : ";
    gquiz.pop_front();
    showdq(gquiz);
  
    cout << "
gquiz.pop_back() : ";
    gquiz.pop_back();
    showdq(gquiz);
  
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Pyramid pattren program in C++ 
Cpp :: C++ Structures (struct) 
Cpp :: ue4 float to fstring 
Cpp :: how to declare a 2d boolean vector in c++ 
Cpp :: insert only unique values into vector 
Cpp :: c++ code for bubble sort 
Cpp :: map declaration c++ 
Cpp :: c++ string size 
Cpp :: c++ cast to type of variable 
Cpp :: c++ string to int 
Cpp :: c++ casting 
Cpp :: change colour of output to terminal c++ 
Cpp :: conditional operator in c++ 
Cpp :: c++ hashmaps 
Cpp :: Palindrome String solution in c++ 
Cpp :: implementing split function in c++ 
Cpp :: convert 2d array to 1d c++ 
Cpp :: c pre-processor instructions 
Cpp :: copying a set to vector in c++ 
Cpp :: ascii cpp 
Cpp :: how to download c++ portable compiler 
Cpp :: how to make a comment in c++ 
Cpp :: size() in c++ SET 
Cpp :: map in c 
Cpp :: double array size c++ 
Cpp :: cpp linked list 
Cpp :: how to grab each character from a string 
Cpp :: initialise 2d vector in c++ 
Cpp :: onoverlapbegin ue4 c++ 
Cpp :: pop off end of string c++ 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =