Data Structure Diary "Definition of Queue"

1. Definition and characteristics of queue

Queue (queue) is a first-in-first-out (First In First Out, FIFO) linear list. It only allows insertions at one end of the table and deletions at the other end. This is consistent with queuing in daily life, where the earliest elements that enter the queue leave first.

In a queue, the end that allows insertion is called the rear, and the end that allows deletion is called the front.

Suppose the queue is quene = (a 1 , a 2 , ..., a n ), then a 1 is the element at the head of the queue, and a n is the element at the end of the queue. The elements in the queue are entered in the order of a 1 , a 2 ,..., a n , and the exit queue can only be exited in this order. Exiting the queue and entering the queue means that only when a 1 , a 2 , ..., After a~n -I~ all leave the queue, a n can exit the queue.

insert image description here

Second, the abstract data type definition of the queue

This Q is actually a data type. Here are some functions of this data structure:

function Initial conditions Function
InitQueue (&Q) - - Constructs an empty queue Q.
Des t royQueue (&Q) Queue Q already exists. Queue Q is destroyed and no longer exists.
ClearQueue (&Q) Queue Q already exists. Clear Q to an empty queue.
QueueEmpty (Q) Queue Q already exists. Returns true if Q is an empty queue, otherwise returns false.
QueueLength(Q) Queue Q already exists. Returns the number of elements in Q, which is the length of the queue.
GetHead(Q} Q is a non-empty queue. Returns the head element of Q.
EnQueue (&Q, e} Queue Q already exists. Insert element e as the new tail element of Q.
DeQueue(&Q, &e) Q is a non-empty queue. Remove the head element of Q and return its value with e.
QueueTr aver se(Q) Q exists and is not empty. From the head of the queue to the tail of the queue, access each data element of Q in turn

3. Examples

For example, when sending data, we have a large amount of data, which cannot be sent at one time, because the amount of export data is limited, then we can only put the data in a queue and send them in chronological order. In this case, it may also have a priority, the queue is always full, and it can also be used as a buffer to send, just like shipping at a port, it is lined up to ship according to time.

insert image description here

Guess you like

Origin blog.csdn.net/qq_43680827/article/details/132144406