Original address: http://www.cnblogs.com/mcgrady/p/3221672.html
On a stack, this one to summarize is our usual queue, I would like to summarize from the following aspects.
1, what is a queue?
2, the storage structure of the queue?
3, the common operation of the queue and implementation code?
1. What is a queue
1, first, the queue is also a special linear table, which is a linear table with restricted operation. It only allows element insertion at one end of the table, and element deletion at the other end. The one end of the allowed insert is called the tail of the queue (rear), and the one end that allows deletion is called the team header (font).
2, for queues, similar to real-life queues, new members are always at the end of the queue, while the queues are always the first to leave the queue, that is, FIFO, so the queue is also known as the first-out table (FIFO).
2. Storage structure of the queue
3. Common operations and code implementations for queues
1, initialize the queue
Idea: Construct an empty queue, with both the head and tail pointer rear set to 0.
2, queue
Idea: If the queue is not satisfied, insert the data x into the position pointed to by the tail pointer rear, and then add the rear to 1.
3, out of the team
Idea: If the queue is not empty, the head pointer is added 1 and the deleted element is returned.
4, take the team head
Idea: If the queue is not empty, the team head element is returned.
5, take the captain.
Idea: The tail pointer rear-head pointer.
6, the team is empty
Idea: You just have to judge whether the head and tail pointers are equal.
7, the team full
Idea: Just judge whether the tail pointer and maxsize are equal
Note: In a non-empty queue, the head pointer always points to the team head element, and the tail pointer always points to the next position of the tail element .
Code implementation:
"Go" Basics Series 4--Queue (code not yet written)