In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
C language to achieve the basic operation of circular queue, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
The circular queue relies on the modular operation to realize the logical loop operation of the data elements in the queue. Compared with the sequential storage implementation of queues, it can avoid the problem of "false overflow".
Header file statement # include # include / * * Circular queue implementation * / / data element upper limit # define MaxSize 50 ElemType data / definition of data type typedef int ElemType;/* structure definition * / typedef struct SqQueue {ElemType data [MaxSize]; / / Array-storing data element int front, / / header pointer rear; / / queue tail pointer} SqQueue;// initialization queue void InitQueue (SqQueue * Q); / / determine whether the queue is empty int EmptyQueue (SqQueue Q) / / queue operation int EnQueue (SqQueue * QMagneElemType e); / / queue operation int DeQueue (SqQueue * QMagazine ElemType * e); / / get queue length int LengthQueue (SqQueue Q); / / get queue head element void GetHead (SqQueue qdepartment ElemType * e); / / print queue void printSqQueue (print Q) Function implements # include "SqQueue.h" / * cyclic queue function implements * / / initializes the queue void InitQueue (SqQueue * Q) {/ / queue head pointer-queue end pointer, and points to the queue head element Q-> front=q- > rear=0;} / / to determine whether the queue is empty int EmptyQueue (SqQueue Q) {/ / the queue head pointer and queue end pointer point to the same element, then the empty queue return q.front==q.rear } / / queue operation int EnQueue (SqQueue * Q rear= ElemType e) {/ / determine whether the team is full if ((Q-> rear+1)% MaxSize==q- > rear) return-1; / / queue operation Q-> data [Q-> rear] = eAccord / add data element-set the value of the tail element to e Q-> rear= (Q-> rear+1)% MaxSize;// tail pointer to move forward, and the tail pointer + + return 1 } / / queue operation int DeQueue (SqQueue * Q front+1 ElemType * e) {/ / determine whether the queue is empty if ((Q-> rear+1)% MaxSize==q- > front) return-1; / / Save data * eqiq-> data [Q-> front]; / / queue operation Q-> front= (Q-> front+1)% MaxSize; return 1;} / / get queue length int LengthQueue (SqQueue Q) {return (q.rear-q.front+MaxSize)% MaxSize } / / get the queue header element void GetHead (SqQueue Q SqQueue ElemType * e) {/ / determine whether the queue is empty if (q.front==q.rear) return; / / get the value of the queue header element * e=q.data [q.front];} / / print queue void printSqQueue (SqQueue Q) {/ / Auxiliary pointer int pIndex; / / print queue element pIndex=q.front; while (pIndex
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.