循环队列
来源:互联网 发布:男士衣服搭配软件 编辑:程序博客网 时间:2024/06/06 11:48
****循环链表是为了避免假溢出现象***
#include <stdio.h>
#include <stdlib.h>#define MAXSIZE 20
typedef int datatype;
typedef struct {
datatype data[MAXSIZE];
int rear,front;
}SeQueue;
SeQueue* InitSeQueue(); //队列初始化
void InSeQueue(); //入队操作
void OutSeQueue(); //出队操作
void FrontSeQueue(); //读队头元素
void EmptySeQueue(); //判队空操作
void main () {
SeQueue *sq;
datatype x1 = 10;
datatype x2;
sq = (SeQueue*)malloc(sizeof(SeQueue));
sq = InitSeQueue();
InSeQueue(sq,x1);
printf("%d\n",sq->data[9]);
EmptySeQueue(sq);
FrontSeQueue(sq);
OutSeQueue(sq,x2);
FrontSeQueue(sq);
}
//指空队
SeQueue* InitSeQueue () {
SeQueue *q;
q = (SeQueue*)malloc(sizeof(SeQueue));
q->front = 6;
q->rear = 8;
q->data[6] = 7;
q->data[7] = 8;
q->data[8] = 9;
return q;
}
//入队
void InSeQueue (SeQueue *q, datatype x) {
if ((q->rear+1) % MAXSIZE == q->front) {
printf("队满");
}
else {
q->rear = (q->rear+1) % MAXSIZE;
q->data[q->rear] = x;
}
}
//出队
void OutSeQueue (SeQueue *q, datatype *x) {
if (q->front == q->rear) {
printf("队空\n");
}
else {
q->front = (q->front+1) % MAXSIZE;
x = q->data[q->front];
}
}
//判队空
void EmptySeQueue (SeQueue *q) {
if (q->front == q->rear)
printf("队空\n");
else
printf("不队空\n");
}
//读队头元素
void FrontSeQueue(SeQueue *q) {
printf("头元素 = %d\n",q->data[q->front]);
}
****循环链表是为了避免假溢出现象***
1 0
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- 循环队列
- UITabBarController自定义风格Item
- iOS笔记UI--汤姆猫小项目(UIbutton使用)
- bzoj1047【haoi2007】理想正方形
- swift2.0 UIImagePickerController 拍照 相册 录像
- 关于android的坐标及Scroll问题
- 循环队列
- unix time stamp(时间戳)和常规时间相互转换的C++代码
- archlinux 使用vnc登陆 raspberrypi2
- hdu2831Plants VS Zombies (贪心)
- 日经春秋 20151009
- 百度 在线编辑器ueditor1_4_3使用方法及配置
- Android开发菜鸟级入门2--尝试升级&绘图
- FTP文件传输协议两种方式的工作原理
- 数组和集合的相互转换