"Go" Basics Series 4--Queue (code not yet written)

Source: Internet
Author: User

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)

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.