Today, I am very depressed. It was nearly a day before I finally figured out what queue is. Although I learned from myself when I used to take the computer Level 3, I learned from the data structure class, And the queue is FIFO. However, many problems have been discovered only by writing a queue (cyclic queue) by myself today. Summarized as follows:
1. With counter queue:
Known:
Queue Length: l the starting subscript of the queue is 0.
Available:
Queue termination Subscript: L-1;
Rear (team end) range: [-1, L-1]
Front (team head) range: [0, l]
Empty team condition: nelement (Team counter) = 0
Team full condition: nelement (Team counter) = L
Sometimes, if a large amount of data is stored, removing the counter can greatly save storage space. However, if the data is directly removed, the team space and team space are the same, and it cannot be determined that the team space and team space are full, you can add a bucket. If the queue length is 5, set the bucket to 6. The detailed rules are as follows:
2. No counter queue:
Known:
Queue Length: l the starting subscript of the queue is 0.
Available:
Actual queue storage space S = L + 1;
Queue termination Subscript: S-1;
Rear (team end) range: [-1, S-1]
Front (team head) range: [0, S]
Team blank condition: Front-Rear = 1 | rear-front = S-1
Team full condition: Rear-front = S-1 | front-Rear = 2
(PS: why are there two conditions? Because rear and front are not necessarily in the same loop,
For example, a = [null, 1, 2, 3, 4, null], front = 1, rear = 4,
If a. insert (5) (pseudoCode, Which means to insert 5 to the head of Team A), then:
A = [null, 1, 2, 3, 4, 5], front = 1, rear =-1)