Stack and queue.

Source: Internet
Author: User

Queue definition and basic operations

1. Definition
A queue is a linear table that only allows insertion at one end and deletion at the other end.



(1) the end that is allowed to be deleted is calledFront).
(2) The end that can be inserted is calledTeam end (rear).
(3) When no element exists in the queue, it is calledEmpty queue.
(4) A queue is also called a linear table of first in first out.FIFO table.
The queue is modified based on the first-in-first-out principle. New members always join the end of the Team (that is, they are not allowed to "gatse"), and each member leaves is always on the head of the queue (they are not allowed to leave in the middle), that is, the current "Oldest" member leaves the team.
[Example] add A1, A2,… to the queue in sequence ,..., After an, A1 is the first element and an is the last element. The order of exiting the queue can only be A1, A2 ,..., An.

2. Basic logical operations of queues
(1) initqueue (q)
Empty team. Construct an empty queue Q.

(2) queueempty (q)
Empty team. If the queue Q is empty, the true value is returned. Otherwise, the false value is returned.

(3) queuefull (q)
The team is full. If the queue Q is full, the true value is returned; otherwise, the false value is returned.
Note:
This operation only applies to the ordered storage structure of the queue.

(4) enqueue (Q, X)
If the queue Q is not full, the element x is inserted to the end of the Q. This operation is shortJoin.

(5) dequeue (q)
If the queue Q is not empty, delete the queue Header element of Q and return this element. This operation is shortTeam-out.

(6) queuefront (q)
If the queue Q is not empty, the first element of the queue is returned, but the status of the queue Q is not changed.

 

For details, refer to the link:

Http://student.zjzk.cn/course_ware/data_structure/web/zhanhuoduilie/zhanhuoduilie3.2.1.htm

Stack and queue.

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.