Call header file: #include <deque>
using namespace Std;
Detailed usage (part):
Deque<type> K; ------defines a deque variable (which was initialized at the time of definition) such as: Deque<int> K;
K.empty ()------See if the example is empty, return 1, not return 0
K.clear ()------Clears all data in the queue
K.push_front (i)------add element I (queue size not preset) from front of existing elements
K.push_back (i)------add element I (queue size not preset) from behind existing elements
K.pop_front ()------Clear the first element
K.pop_back ()------Clear the last element
K.front ()------Display the first element, such as N = K.front ();
K.back ()------Display the last element
K.size ()------Output The number of existing elements
#include <stdio.h>
#include <deque>
using namespace std;
int main (void)
{
int i;
int a[10] = {0,1,2,3,4,5,6,7,8,9};
deque<int> Q;
for (i=0;i<=9;i++)
{
if (i%2==0)
Q.push_front (a[i));
else
Q.push_back (a[i]);
} /* At this time the contents of the queue is: {8,6,4,2,0,1,3,5,7,9}*/
q.pop_front ();
printf ("%d\n", Q.front ()); /* Clears the first element and outputs the first (6)/
q.pop_back ();
printf ("%d\n", Q.back ()); /* Clears the last element and outputs the last (7) */return
0;
}