1. Stack
The stack template class is defined in the <stack> header file.
The stack template class requires two template parameters: one is the element type and the other is the container type, but only the element type is necessary.
When the container type is not specified, the default container type is deque.
The sample code for defining a stack object is as follows:
Stack <int> S1;
Stack <string> S2;
Basic stack operations include:
Stack entry, for example, S. Push (X );
Out stack, for example, S. Pop (); note that the out stack operation only deletes the top element of the stack and does not return this element.
Top access stack, for example, S. Top ()
Judge whether the stack is empty. For example, S. Empty (). If the stack is empty, true is returned.
Number of elements in the access stack, for example, S. Size ().
2. Queue
The queue template class is defined in the <queue> header file.
Similar to the stack template class, the queue template class also requires two template parameters, one of which is the element type and the other is the container class.
Type, element type is necessary, container type is optional, the default is deque type.
The sample code for defining a queue object is as follows:
Queue <int> q1;
Queue <double> Q2;
Basic queue operations include:
Join the queue, for example, Q. Push (x); Connect X to the end of the queue.
For example, Q. Pop (); the first element of the queue is displayed. Note that the value of the element to be popped up is not returned.
The first element of the access queue, such as Q. Front (), which is the first element to be pushed into the queue.
Access the elements at the end of the team, for example, Q. Back (), that is, the elements that are finally pushed into the queue.
Determines whether the queue is empty. For example, Q. Empty (). If the queue is empty, true is returned.
Number of elements in the access queue, for example, Q. Size ()
Use of # include <stack> and # include <queue>