Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is a queue?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

What this article shares to you is about what is a queue. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Queue is a special kind of linear table. Like the stack, the queue is a linear table whose operation is limited; the end of the insert operation is called the end of the queue, and the end of the delete operation is called the head of the queue; when there are no elements in the queue, it is called the empty queue.

Queue is a special linear table, which is special in that it only allows deletion at the front end of the table (front) and insert operation at the back end of the table (rear). Like the stack, queue is a linear table with limited operations. The end of the insert operation is called the end of the queue, and the end of the delete operation is called the head of the line. When there are no elements in the queue, it is called an empty queue.

The data element of a queue is also called a queue element. Inserting a queue element into the queue is called queuing, and removing a queue element from the queue is called dequeuing. Because queues are only allowed to be inserted at one end and deleted at the other end, only the earliest elements that enter the queue can be deleted from the queue first, so the queue is also known as the first-in-first-out (FIFO-first in first out) linear table.

Linked list implementation of queue

In the process of queue formation, we can use the principle of linear linked list to generate a queue.

The queue based on linked list is inefficient to create and delete nodes dynamically, but it can grow dynamically.

When FIFO (first in first out) is used in the queue, new elements (elements waiting to enter the queue) are always inserted at the end of the linked list, and always read from the head of the linked list. Read one element at a time and release one element at a time. So-called dynamic creation, dynamic release. Therefore, there is no spillover and other problems. Because the linked list is formed indirectly by the structure, it is also convenient to traverse.

Basic operation of queue

(1) initialize queue: Init_Queue (Q), initial condition: queue Q does not exist. Operation result: an empty team was constructed.

(2) join the team operation: In_Queue (QMagol x), the initial condition: the team Q exists. Operation result: for the existing queue Q, insert an element x to the end of the queue, and the queue changes

(3) out-of-line operation: Out_Queue (QPowerX). Initial condition: team Q exists and is not empty. Operation result: delete the first element of the team and return its value, and the team changes.

(4) read the queue head element: Front_Queue (QQuery x). Initial condition: team Q exists and is not empty. Operation result: read the queue head element and return its value. The team remains unchanged.

(5) judging team empty operation: Empty_Queue (Q), initial condition: team Q exists, operation result: if Q is empty team, return 1, otherwise return 0.

The above is what the queue is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report