Queues and stacks are similar, but unlike stack requirements to add and delete data items on the same side, they are first-in-class and in-line with life.
Common operations are
Queue (Enqueue)
The team (dequeue)
Application of the queue:
The breadth-first search algorithm of graphs;
Priority queue, which is a characteristic value or precedence based on the element that is being taken when the element is fetched
Operating system work scheduling, if the work priority is the same, then the first-come-first-done principle
For spooling, the data is now written to disk, and the printer will then output the first deposit
The queue looks simple, but it actually hides a lot of subtle details.
The first is the memory representation problem, usually using an array or a linked list to represent the queue
If you keep adding elements at the end of the team and deleting elements from the team header, the data structure of the queue will migrate slowly in memory, and simply using arrays is not efficient, such as the head pointer reaching the end of the team.
If you use data, you can use an array loop to avoid this problem, the loop buffer (circular buffer), the ring queue.
If you use a linked list to delete and add nodes in a queue, the available memory is fragmented when the nodes are allocated and freed.
Workaround:
1. Create a node pool by using a function
2, create a list of unused nodes, when the project is added to the queue, the node from the idle list to move to the queue, when the project out of the team, the node is returned to the free table.
Bidirectional queue
Enter a restrictive bidirectional queue
Output restrictive bidirectional queue
The implementation of the ring queue has to be understood again.
Queue of data structures