Talk C Chestnut Bar (22nd time: C-language Instance-queue one)

Source: Internet
Author: User


Ladies and gentlemen, crossing, the last time we were talking about an example of an expression evaluation, the sample uses a stack, which we're talking about.

Brother: Queue.

Gossip Hugh, words return to the positive. Let's talk about C chestnuts together.


The queue we're talking about here is an abstract data structure, and we don't have to think too abstract, haha, in fact it and our daily life

See the same queue. No matter what. Let's give an easy-to-understand example: Everyone has a line when they go on vacation.

The experience of buying tickets. The visitors were queued in front of the form at the ticket point. The ticket vendor sells the tickets to the front row of the queue

Guests, buy tickets for tourists take the tickets hing high out of the queue, just came to the ticket at the end of the queue of tourists waiting to buy

Tickets. In this example. The long line is considered a queue for visitors to buy tickets to be lined up next to the ticket office. Queue

Can be seen as the elements that are stored in the queue. Visitors who buy tickets leave the queue and can be seen as removing elements from the queue and want to

Visitors who buy tickets are queued to be seen as inserting elements into the queue.

I said so. Do you still think the queue is abstract? Assuming that the sleep

Abstract words. The next time you buy tickets, pay more attention to it.


Let's take a look at the characteristics of the queue:

1. The queue has a head and a tail.

For example, just in the sample. Visitors who buy tickets first can be seen as the head of the queue. The tourists who just lined up in the queue

Can be seen as the tail of a queue.


2. Removing elements from the queue can only be done at the head of the queue. For example, the visitor who bought the ticket in the sample just now leaves the queue and can be seen as a team

The column header deletes an element.


3. Inserting elements into the queue can only be done at the end of the queue. For example, the visitor who wants to buy tickets in the sample is queued. can be seen as

Inserts an element into the queue.


4. The elements in the queue adhere to the "FIFO" rule. For example, the first line of visitors in the sample is to buy tickets first.


Crossing, the text does not write code, the specific code put in my resources, we can click here to download the use.

This queue is

Implemented in the form of sequential storage. Detailed into the code is the use of an array to act as a queue.


You crossing. A sample of the queue we're going to talk about here.

See what else is in the back. and listen to tell.



Talk C Chestnut Bar (22nd time: C-language Instance-queue one)

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.