当前位置:网站首页>Circular queue
Circular queue
2022-07-23 11:59:00 【Look, that's a licking dog】
#include <stdio.h>
#include <malloc.h>
#define MAXSIZE 20
typedef int T;
typedef struct Quene
{
T data[MAXSIZE];
int front;// Head position
int rear;// Tail position
}*quene;
bool InitQuene(quene q)// initialization
{
if (!q)
return false;
q->front = 0;
q->rear = 0;
return true;
}
bool ClearQuene(quene q)// Qingdui
{
if (!q)
return false;
q->front = q->rear = 0;
return true;
}
bool Is_Empty(quene q)// The disk is empty
{
return q->front == q->rear;
}
bool Is_Full(quene q)// Full sentence
{
return (q->rear + 1)%MAXSIZE == q->front;
}
int GetLength(quene q)// The number of data
{
return (q->rear - q->front + MAXSIZE) % MAXSIZE;
}
T GetHead(quene q)// Get team leader elements
{
if (Is_Empty(q))
return -1;
return q->data[q->front];
}
bool Push(quene q,T val)// The team
{
if (Is_Full(q))
return false;
q->data[q->rear] = val;
q->rear = (q->rear + 1) % MAXSIZE;
return true;
}
T Pop(quene q)// Out of the team
{
if (Is_Empty(q))
return false;
T tmp = q->data[q->front];
q->front = (q->front + 1) % MAXSIZE;
return tmp;
}
void Show(quene q)// Traverse
{
if (Is_Empty(q))
return;
int i = q->front;
while (i != q->rear)
{
printf("%d ", q->data[i]);
i = (i + 1) % MAXSIZE;
}
printf("\n");
}
//int main()
//{
// quene q;
// q = (quene)malloc(sizeof(Quene));
// InitQuene(q);
// for (int i = 1; i <= 10; i++)
// {
// Push(q,i);
// }
// Show(q);
// for (int i = 1; i <= 5; i++)
// {
// printf("%d ", Pop(q));
// }
// printf("\n");
// Show(q);
// return 0;
//}
边栏推荐
猜你喜欢

九、实用类

LearnOpenGL - Introduction

Machine learning algorithm for large factory interview (5) recommendation system algorithm

使用飞桨的paddleX-yoloV3对钢材缺陷检测开发和部署

11、多线程
![[uiautomation] key instructions (and three call methods) + common mouse actions +sendkeys+inspect learning](/img/9c/84c92c894b19820560e14502472c8b.png)
[uiautomation] key instructions (and three call methods) + common mouse actions +sendkeys+inspect learning

8、 Collection framework and generics

Definition and application of method

數倉4.0筆記——用戶行為數據采集四

10. I/o input / output stream
随机推荐
VMware uses wireless network card NAT to access the Internet under Windows
Method of recognizing b value from DICOM tag in DWI image
高德定位---权限弹框不出现的问题
ChaosLibrary·UE4开坑笔记
飞桨高层API实现图像去雨
ninja启动过程
双端队列
MySQL storage engine
[hudi]hudi compilation and simple use of Hudi & spark and Hudi & Flink
[metric] use Prometheus to monitor flink1.13org.apache.flink.metrics
数仓4.0笔记——用户行为数据采集二
Data warehouse 4.0 notes - data warehouse environment construction - Yan configuration
MySQL invalid conn troubleshooting
Unable to negotiate with port 51732: no matching host key type found. Their offer:
DBA command
8、 Collection framework and generics
10. I/o input / output stream
1. Know the database
The user logs in continuously (interruption is allowed) to query SQL
3.1、对DQL简化补充