初学数据结构之队列
来源:互联网 发布:网络舆情重要性 编辑:程序博客网 时间:2024/05/21 09:33
一.数组实现(只用N-1个空间)#define MaxSize 10typedef struct {int Data[MaxSize];int rear;int front;}Quene;void AddQ(Quene *Ptrq,int item){if((Ptrq->rear+1)%MaxSize==Ptrq->front){printf("队列满");return ; }Ptrq->rear=(Ptrq->rear+1)%MaxSize;Ptrq->Data[Ptrq->rear]=item;}int DelectQ(Quene *Ptrq){if(Ptrq->front==Ptrq->rear){printf("队列空");return ERROR; }else{Ptrq->front=(Ptrq->front+1)%MaxSize;return Ptrq->Data[Ptrq->front];}}二.链表实现typedef struct Node{int Data;struct Node *Next;}QNode;typedef struct {QNode *rear;QNode *front;}LinkQuene;LinkQuene *Ptrq;int DelectQ(LinkQuene *Ptrq){QNode *FrontCell;int FrontElem;if(Ptrq->front==NULL){printf("队列空");return ERROR;}FrontCell=Ptrq->front;if(Ptrq->front==Ptrq->rear){Ptrq->front=Ptrq->rear=NULL;}else{Ptrq->front=Ptrq->front->Next;}FrontElem=FrontCell->Data;free(FrontCell);return FrontElem;}void AddQ(LinkQuene *Ptrq,int item){QNode *RearCell;if(Ptrq->front==NULL){RearCell=(struct Node *)malloc(sizeof(struct Node));Ptrq->rear=Ptrq->front=RearCell;RearCell->Data=item;}else{RearCell=(struct Node *)malloc(sizeof(struct Node));RearCell->Data=item;RearCell->Next=Ptrq->rear->Next;Ptrq->rear->Next=RearCell;Ptrq->rear=RearCell;}}
0 0
- 数据结构初学之:队列
- 初学数据结构之队列
- 初学数据结构之堆栈
- 初学数据结构之排序
- 数据结构之队列(链式队列)
- 数据结构之队列(数组队列)
- 数据结构之队列-顺序队列
- 初学数据结构之二叉树
- 数据结构之循环队列
- 数据结构之顺序队列
- 数据结构之链队列
- java数据结构之队列
- 数据结构之队列
- 数据结构复习之【队列】
- 内核数据结构之队列
- 数据结构之队列实例
- 数据结构学习之队列
- 复习数据结构之队列
- XPOSED源码研究之XposedInstaller(6)DownloadFragment
- hdu 3465 Life is a Line 树状数组求逆序数
- 【asp.net】常用内置对象(session,Application,ViewSate)
- [Elasticsearch] 过滤查询以及聚合(Filtering Queries and Aggregations) 5
- JAVA 集合
- 初学数据结构之队列
- git学习笔记
- LeetCode(39) Combination Sum
- 欢迎使用CSDN-markdown编辑器
- 位运算
- hdoj 3062 Party 【2-sat入门 :布尔表达式建边 有向图tarjan求SCC】 【离散没学好是硬伤】
- openGL 深度测试
- sql 工作用到几个函数
- 使用Android开发照相功能小程序实例