StackA stack is a special linear table that can be inserted and deleted only at one end. Accumulate items in buckets, pile them in at the bottom, and then pile up on one piece. Take the walk, can only be taken from one of the above. Both the heap and the fetch are at the top, and the bottom is generally motionless. A stack is a data structure similar to a bucket of stacked items, where one end is called the top of the stack and the other end is called the bottom of the stack. Insertion is generally called a stack (PUSH), and deletion is called a fallback (POP). Stacks are also known as LIFO tables (LIFO tables).
The basic operation of the stack is as follows:
include<stack>//header file stack< data type > variable name//definition stack such as: stack<int>a;a.push (variable)//Stack a.top ()//return stack top element A,pop ()// Stack a.size ()//Returns the number of elements in the stack a.empty ()//returns True if the stack is empty, otherwise false
Queue
A queue is defined at one end to be inserted, and the other end to delete a special linear table. Just like in line to buy things, the people in front of the purchase of things to leave the team (delete), and later people are always in the queue (inserted). Usually the deletion and insertion of the queue are called out and queued respectively. Allow one end of the team to be called the team head, allowing one end of the queue to be called the team tail. All data items that need to enter the team can only be entered from the end of the team, and the data items in the queue can only be departed from the team head. This table is also known as the FIFO (first-in-one-out) table because it is always first out of the queue (the first person to buy something first). The queue basic operations are as follows:
#include <queue>//header file queue< data type > variable name//definition queue such as: Queue<int>aa.empty ()//If the queue is empty returns True, otherwise false A.size ()//Returns the number of elements in the queue A.pop ()//deletes the first element of the queue but does not return its value A.front ()//Returns the value of the first element of the team, but does not delete the element A.push ()//At the end of the team press into the new element A.back ()//Returns the value of the tail element of the queue, but does not delete the element
Getting Started with stacks and queues