进出队列
来源:互联网 发布:effective java 下载 编辑:程序博客网 时间:2024/04/29 12:51
进出队列代码如下
#include <stdio.h>#include <stdlib.h>#define OK 1#define FALSE 0#define ERROR 0#define TRUE 1#define M 100typedef struct { int elem[M]; int rear; int front; } SqQueue;typedef int Status;//初始化队列 Status SqQueueInit(SqQueue *S){ S->front = S->rear = 0; return OK;}//入队函数 int SqQueueInsert(SqQueue *S, int x){ if ((S->rear + 1) % M == S->front) { return FALSE; } S->elem[S->rear] = x; S->rear = (S->rear + 1) % M; return TRUE;}//出队函数 int SqQueueDelete(SqQueue *S, int *x){ if (S->rear == S->front) { return FALSE; } *x=S->elem[S->front] ; S->front = (S->front + 1) % M; return TRUE;}int main() { SqQueue S; int j; int m; SqQueueInit(&S); //初始化函数 SqQueueInsert(&S,55); //入队函数 SqQueueInsert(&S,32); SqQueueInsert(&S,16); SqQueueInsert(&S,51); SqQueueInsert(&S,34); for (j = 0; j < M; ++j) { if(SqQueueDelete(&S,&m)==OK) //出队函数 printf("%d ",m); } return 0;}
运行结果
阅读全文
0 0
- 进出队列
- 队列进出原则
- 进出队列(含上溢,下溢处理)
- 带结构体的队列 进出实例
- 栈与队列(一)进出栈(含二转十进制栈应用)
- 链表与表——随心所欲地进出任何队列
- 进出异常
- 进出登记
- 进出栈
- 进出栈
- 进出纯DOS模式
- activity进出动画
- openfire查看进出包
- 进出风口了
- 埃及进出品规定
- 火车进出铁轨问题
- 进出股市感受
- Android Activity进出动画
- mysql 索引
- CSmove及跳跃
- Linux切换用户
- ANDROID样式的开发:PROPERTY ANIMATION篇
- Linux入门,这七大习惯得有!
- 进出队列
- Ubuntu下pip的安装及配置
- OpenCV3图像形态学处理
- js设计模式基础
- Git常用命令清单总结
- 第五天-python数据类型-1
- 自定义View倒计时
- 【Java学习笔记】44:JFrame布局管理
- Leetcode-BFS广度优先搜索