Data Structure Basics (5)--Queue and loop queue details--static mode

Source: Internet
Author: User

Specific applications for queues:

all event-related operations have a queue shadow.

(for example, the operating system considers advanced to be processed first)


Defined:

A kind of storage structure that realizes "FIFO"

Classification:

Chained queues: implemented with linked lists


Static queue: Implemented with arrays

A static queue must always be a circular queue, in order to reduce

Memory waste.





Loop queue:1. Why a static queue must be a circular queue

If the queue is implemented in a traditional array of arrays, the rear and front pointers can only + not be used, regardless of whether the team is queued or out.

The subscript of an array element that is smaller than the subscript of the F element is wasted.

How does the loop queue work?

When this occurs, if you still need to insert the element, then F points to the next position, that is, 5,r points to the next position, which is 0.


So, we're inserting an element "country" and then deleting it?


This is called the loop queue.

2. The cyclic queue needs several parameters to determine its meaning

Requires 2 parameters to determine

Front

Rear

3.meaning of the various parameters of the loop queue

2 parameters different meanings in different situations ?

It is recommended that beginners remember first and then slowly experience

1) Queue initialization

The values for both front and rear are zero, and the queue is empty when initialized.

2) Queue non-empty

The first element of the Front team column

Rear represents the next element of the last valid element

3) Queue Empty

The values of front and rear are equal, but not necessarily zero

4, the Circle team included in the team pseudo algorithm explanation

You need to determine if r points to the last element of the array.

Two steps to complete:

1) Place the value in the location represented by R

2) Move r back, correct notation is rear = (rear+1)% array length

Wrong wording: rear=rear+1;

5, circular team list of the team pseudo algorithm explained

Front = (front+1)% array length

6, how to determine whether the circular queue is empty

If the values of front and rear are equal,

The queue must be empty

7. How to determine if the loop queue is full



In this case, if you insert f,r again, point to the same element. If that's the case, you can't tell if the queue is empty or full.

So in order to determine whether the loop queue is full, there are two ways:

1. Add more parameters to a table ID

2, less use a queue of elements (only one, does not affect)

If R and F are next to each other (f in the next position of R), the queue is full

In C language Description:

If ((r+1)% array length ) ==f

queue is full

Else

Queue dissatisfaction

Data Structure Basics (5)--Queue and loop queue details--static mode

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.