Stack stack, no iterator, supports the push () method. After going forward, go first, top () returns the top element, and pop () removes the top element.
Deque dual-end queue, supports iterator, has push_back () method, and is similar to vector, has more pop_front than vector, push_front Method
Queue queue, first-in-first-out, does not support iterators, there is a push () method, pop () removes the first element, Front () returns the first element
The Code is as follows:
# Include <iostream>
# Include <stack>
# Include <string>
Using namespace STD;
Int main (){
Stack <int> S;
For (INT I = 1; I <= 10; ++ I ){
S. Push (I );
}
For (Int J = 0; j <10; ++ J ){
Cout <S. Top () <"";
S. Pop ();
}
Cout <Endl;
System ("pause ");
Return 0;
}
# Include <iostream>
# Include <string>
# Include <deque>
Using namespace STD;
Int main (){
Deque <int> q;
For (INT I = 0; I <10; ++ I ){
Q. push_back (I );
}
Cout <q. Front () <Endl;
For (deque <int >:: iterator iter = Q. Begin (); iter! = Q. End (); ++ ITER ){
Cout <* ITER <"";
}
Cout <Endl;
Cout <q. Back () <Endl;
System ("pause ");
Return 0;
}
# Include <iostream>
# Include <queue>
# Include <string>
Using namespace STD;
Int main (){
Queue <int> q;
For (INT I = 0; I <10; ++ I ){
Q. Push (I );
}
For (INT I = 0; I <10; ++ I ){
Cout <q. Front () <"";
Q. Pop ();
}
Cout <Endl;
System ("pause ");
Return 0;
}