This is a creation in Article, where the information may have evolved or changed.
First, what is a queue
The queue in the data structure is the imitation of the line in reality. If the dog in line to the toilet, the new dog platoon to the end of the queue, the top dog spilled urine away, behind the heel. You can see that there are two features of the queue:
(1) The new comes in the tail of the team;
(2) The front of the business after the departure, followed by a follow up.
According to the characteristic, the computer brick family induces the following queue structure.
Queue abbreviation FIFO, meaning oneself realize.
Second, the structure of the queue
Continue brother David's demolition hand. Queues are split into containers and linked lists, respectively, by structure and single-linked list, for example.
Third, the interface description and implementation
1. Init
Initializing the queue is actually initializing the inside of the single-linked list.
Func (Queue *queue) Init () {
LST: = new (List)
(*queue). List = LST
Lst. Init ()
}
2, Enqueue
A small dog with urine is in line.
Func (Queue *queue) Enqueue (data Object) bool {
Return (*queue). List. Append (data)
}
3, Dequeue
The little dog who spilled urine is out.
Func (Queue *queue) Dequeue () Object {
Return (*queue). List. RemoveAt (0)
}
4. Peek
It's a special hobby to peek at a team-headed dog from time to time.
Func (Queue *queue) Peek () Object {
Return (*queue). List. First ()
}
5, GetSize
Limited space, the team can not be too long, you have to keep track of the length of the team.
Func (Queue *queue) GetSize () UInt64 {
Return (*queue). List. GetSize ()
}
Iv. Summary
Here's a summary of David Brother does not say nonsense, and the same as the previous section, if the two-way list or other structure can be implemented queue? Queues can be applied in sequential processing streams, including event loops, concurrent processing, operation synchronization, and so on.
Code download
1364 Reads