Queue is a special linear list. It only allows deletion operations at the front end (front) of the table, and insertion operations at the rear end (rear) of the table. Like the stack, the queue is a linear table with restricted operations; the end where the insertion operation is performed is called the queue. The end where the deletion operation is performed is called the head of the queue; when there are no elements in the queue, it is called an empty queue.
The queue is a special linear table. The special thing is that it only allows deletion operations at the front end (front) of the table. The backend (rear) of the table performs insertion operations. Like the stack, the queue is a linear table with limited operations.The end that performs the insertion operation is called the tail of the queue, and the end that performs the deletion operation is called the head of the queue. When there are no elements in the queue, it is called an empty queue.
The data elements of the queue are also called queue elements.Inserting a queue element into the queue is called enqueuing, and deleting a queue element from the queue is called dequeuing. Because the queue only allows insertion at one end and deletion at the other end, only the element that enters the queue earliest can be deleted from the queue first, so the queue is also called a first-in-first-out (FIFO—first in first out) linear list.
Linked list implementation of queue
In the formation process of the queue, the principle of linear linked list can be used to generate a queue.
The queue based on the linked list needs to dynamically create and delete nodes, which is less efficient, but can grow dynamically.
The queue uses FIFO (first in first out). New elements (elements waiting to enter the queue) are always inserted into the end of the linked list, and when reading, they always start reading from the head of the linked list. . Each time one element is read, one element is released. The so-called dynamic creation and dynamic release. Therefore, there are no problems such as overflow. Since the linked list is indirectly formed by the structure, it is also convenient to traverse.
Basic operations of queue
(1) Initialization queue: Init_Queue(q), initial condition: queue q does not exist. Operation result: An empty queue is constructed;
(2) Queue entry operation: In_Queue(q,x), initial condition: Queue q exists. Operation result: For the existing queue q, insert an element Empty, operation result: delete the first element of the queue and return its value, the queue changes;
(4) Read the first element of the queue: Front_Queue(q,x), initial condition: queue q exists and is not empty, Operation result: Read the queue head element and return its value, the queue remains unchanged;
(5) Queue empty operation: Empty_Queue(q), initial condition: queue q exists, operation result: if q is empty Team returns 1, otherwise returns 0.
For more related knowledge, please visit
PHP Chinese websiteThe above is the detailed content of What does queue mean?. For more information, please follow other related articles on the PHP Chinese website!