Queue of GO data structures

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.