当前位置:网站首页>Queue storage and circular queue
Queue storage and circular queue
2022-04-23 03:10:00 【Dead of night code】
One 、 The storage structure of the queue
1、 The physical storage of queues can be in a sequential storage structure , Chain storage structure can also be used . The storage methods of corresponding queues are also divided into two types , namely Sequential and chained queues .
2、 Sequential queues can be represented by one-dimensional arrays as follows :
#define MAXQSIZE 100 // Maximum queue length
Typedef struct {
QElemType *base; // Initialize the dynamic allocation of storage space
int front; // The head pointer
int rear; // Tail pointer
}SqQueue;
Two 、 Basic operation statement of circular queue
1、 Initial of queue :front=rear=0;
2、 Element entry :base[rear]=x; rear++;
3、 Element queue :x=base[front];front++;
4、 Air force sign :front==rear;
5、 The team is full : In order to prevent the team full sign from being the same as the team empty sign , It will use one less element space , That is, the queue space size is m when , Yes m-1 The first element is considered to be the team full . In this way, the conditions for judging the team empty remain the same , Immediate leadership 、 When the value of the tail pointer is the same , The team thinks it's empty ; When the tail pointer adds... In the sense of loop 1 Followed by a pointer equal to the head , Think the team is full . therefore , The condition for a full queue in a circular queue is :(rear+1)%MAXQSIZE==front.
3、 ... and 、 False overflow of sequential queue
1、 Definition : The array storage area used by the system as a queue is not full yet , But the queue overflowed , We call this phenomenon " False spillover ".
2、 reason : Because when the elements join the team The head pointer When the element moves forward and out of the queue, the tail pointer also moves forward , When the head pointer is out of vector space , At this time, the whole vector space and queue are not full, but " Overflow " The phenomenon .
3、 resolvent : Think of team space as a circular table , I.e. assigned to the queue m Storage units can be recycled , When rear by maxqsize when , If the beginning of the vector is empty , You can use the empty space from the beginning . When front by maxqsize when , Is the same .
Four 、 Circular alignment
1、 Storage mode of circular queue :base[0] Connect to base[MAXQSIZE -1] after , if rear+1==M, Then order rear=0;
2、 Loop queue insert elements and delete
① Insert elements : Q.base[Q.rear]=x;
Q.rear= (Q.rear+ 1)% MAXQSIZE;
② Remove elements : x= Q.base[s.front]
Q.front=(Q.front+ 1)% MAXQSIZE
版权声明
本文为[Dead of night code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230307502212.html
边栏推荐
- How does Microsoft solve the problem of multiple PC programs
- TP5 email (2020-05-27)
- MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
- Aspnetcore configuration multi environment log4net configuration file
- 中后二叉建树
- 编码电机PID调试(速度环|位置环|跟随)
- Binary tree
- Source Generator实战
- Openfeign service call
- Xamarin effect Chapter 22 recording effect
猜你喜欢

MYSQL03_ SQL overview, rules and specifications, basic select statements, display table structure

編碼電機PID調試(速度環|比特置環|跟隨)

最通俗易懂的依赖注入之生命周期

2022年度Top9的任务管理系统

svg标签中利用<polygon/>循环数组绘制多边形

Vs code setting line feed

微软是如何解决 PC 端程序多开问题的

C# 11 的这个新特性,我愿称之最强!

ASP. Net and ASP NETCORE multi environment configuration comparison

Use of slice grammar sugar in C #
随机推荐
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
Openfeign details show
最通俗易懂的依赖注入之生命周期
ASP.NET和ASP.NETCore多环境配置对比
Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s
Swap the left and right of each node in a binary tree
Fundamentals of software testing and development
Laravel's own paging query
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
Source Generator实战
ASP. Net and ASP NETCORE multi environment configuration comparison
.Net Core 限流控制-AspNetCoreRateLimit
be based on. NETCORE development blog project starblog - (2) environment preparation and creation project
如果通过 C# 实现对象的深复制 ?
The most easy to understand service container and scope of dependency injection
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
2022年度Top9的任务管理系统
yes. Net future
Xamarin效果第二十二篇之录音效果
【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持