当前位置:网站首页>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
边栏推荐
- Tips in MATLAB
- 編碼電機PID調試(速度環|比特置環|跟隨)
- 2022年P气瓶充装培训试题及模拟考试
- C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
- 搭建XAMPP时mysql端口被占用
- svg标签中利用<polygon/>循环数组绘制多边形
- 樹莓派開發筆記(十二):入手研華ADVANTECH工控樹莓派UNO-220套件(一):介紹和運行系統
- PID debugging of coding motor (speed loop | position loop | follow)
- AOT和单文件发布对程序性能的影响
- 【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
猜你喜欢
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
Vs code setting line feed
TP5 email (2020-05-27)
Judge whether there is a leap year in the given year
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
类似Jira的十大项目管理软件
xutils3修改了我提报的一个bug,开心
Ningde's position in the times is not guaranteed?
Drawing polygons with < polygon / > circular array in SVG tag
svg标签中利用<polygon/>循环数组绘制多边形
随机推荐
yes. Net future
Impact of AOT and single file release on program performance
Establishing and traversing binary tree
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
Middle and rear binary tree
准备一个月去参加ACM,是一种什么体验?
7-11 rearrange the linked list (25 points)
Distributed system services
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
c#可变参数params的介绍
2022T电梯修理考试模拟100题及在线模拟考试
C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
在.NE6 WebApi中使用分布式缓存Redis
利用正反遍历来解决“字符的最短距离”问题
全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆
xutils3修改了我提报的一个bug,开心
C syntax pattern matching [switch expression]
最通俗易懂的依赖注入与控制反转
AspNetCore配置多环境log4net配置文件
2022山东省安全员C证上岗证题库及在线模拟考试