队列的顺序存储及其基本操作
2013-08-15 09:57
405 查看
#include <stdio.h> #include <stdlib.h> #define QueueSize 10 typedef struct { char data [QueueSize]; int front,rear; }SqQueue; void InitQueue(SqQueue &qu) //初始化队列 { qu.rear=qu.front=0; } int EnQueue(SqQueue &qu, char x) //进队 { if((qu.rear+1)%QueueSize==qu.front) return 0; else { qu.rear=(qu.rear+1)%QueueSize; qu.data[qu.rear]=x; return 1; } } int DeQueue(SqQueue &qu,char &x) //出队 { if(qu.rear==qu.front) return 0; else { qu.front=(qu.front+1)%QueueSize; x=qu.data[qu.front]; return 1; } } int GetHead(SqQueue qu,char x) //取队头元素 { if(qu.rear=qu.front) return 0; else { x=qu.data[(qu.front+1)%QueueSize]; return 1; } } int QueuEmpty(SqQueue qu) //判断队空 { if(qu.front==qu.rear) return 1; else return 0; } int main() { SqQueue qu; char e; InitQueue(qu); printf("Queue is %s\n",(QueuEmpty(qu)==1?"Empty":"Not Empty")); printf("a in Queue\n");EnQueue(qu,'a'); printf("b in Queue\n");EnQueue(qu,'b'); printf("c in Queue\n");EnQueue(qu,'c'); printf("d in Queue\n");EnQueue(qu,'d'); printf("Queue is %s\n",(QueuEmpty(qu)==1?"Empty":"Not Empty")); GetHead(qu,e); printf("The 1st Character in Queue: %c\n",e); printf("Order of this Queue: "); while(!QueuEmpty(qu)) { DeQueue(qu,e); printf("%c ",e); } printf("\n"); return 0; }
相关文章推荐
- 队列的顺序存储及其基本操作
- 链表,顺序表的基本操作及其实现的栈与队列
- 队列的顺序存储的基本操作.....
- 队列的顺序存储的基本操作.....
- 栈的顺序存储及其基本操作
- 实验3:栈和队列的基本操作实现及其应用——顺序队列和链队列
- 栈的顺序存储及其基本操作
- 实验三:栈和队列的基本操作实现及其应用——顺序栈
- 顺序队列基本操作
- 队列的定义及其基本操作
- 数据结构笔记(一)线性表的顺序表示和基本操作及其顺序表实现的集合运算(A-B)U(B-A)实例
- 队列的链式存储及其基本运算
- 顺序队列的基本操作
- 实验三 栈和队列的基本操作实现及其应用
- 实验4:栈和队列的基本操作实现及其应用——循环队列
- 数据结构的串的顺序存储的基本操作(学习历程)
- 串的静态顺序存储基本操作
- 队列的链式存储及其基本运算
- 队列的定义与操作(顺序存储)
- 线性表的顺序存储的基本操作