Queue definition and basic operations
1. Definition
A queue is a linear table that only allows insertion at one end and deletion at the other end.
(1) the end that is allowed to be deleted is calledFront).
(2) The end that can be inserted is calledTeam end (rear).
(3) When no element exists in the queue, it is calledEmpty queue.
(4) A queue is also called a linear table of first in first out.FIFO table.
The queue is modified based on the first-in-first-out principle. New members always join the end of the Team (that is, they are not allowed to "gatse"), and each member leaves is always on the head of the queue (they are not allowed to leave in the middle), that is, the current "Oldest" member leaves the team.
[Example] add A1, A2,… to the queue in sequence ,..., After an, A1 is the first element and an is the last element. The order of exiting the queue can only be A1, A2 ,..., An.
2. Basic logical operations of queues
(1) initqueue (q)
Empty team. Construct an empty queue Q.
(2) queueempty (q)
Empty team. If the queue Q is empty, the true value is returned. Otherwise, the false value is returned.
(3) queuefull (q)
The team is full. If the queue Q is full, the true value is returned; otherwise, the false value is returned.
Note:
This operation only applies to the ordered storage structure of the queue.
(4) enqueue (Q, X)
If the queue Q is not full, the element x is inserted to the end of the Q. This operation is shortJoin.
(5) dequeue (q)
If the queue Q is not empty, delete the queue Header element of Q and return this element. This operation is shortTeam-out.
(6) queuefront (q)
If the queue Q is not empty, the first element of the queue is returned, but the status of the queue Q is not changed.
For details, refer to the link:
Http://student.zjzk.cn/course_ware/data_structure/web/zhanhuoduilie/zhanhuoduilie3.2.1.htm
Stack and queue.