队列,数组式
来源:互联网 发布:python爬虫教程 pdf 编辑:程序博客网 时间:2024/06/05 19:05
就当作学习数据结构的记忆吧
//队列,数组式#include <stdio.h>#include <stdlib.h>#define ELEMTYPE int#define STATUS int#define STRUCTSIZE sizeof(QUEUE)#define ELEMSIZE sizeof(ELEMTYPE)typedef struct QUEUE{ELEMTYPE *epData;int iFront;int iRear;int iQueueSize;//循环队列存在闲置节点,该值不包含闲置节点}QUEUE,*QUEUEP;QUEUEP queueInit(int iSize);STATUS isFull(QUEUEP spQueue);STATUS isEmpty(QUEUEP spQueue);STATUS queueInput(QUEUEP spQueue,ELEMTYPE eTemp);STATUS queueOutput(QUEUEP spQueue,ELEMTYPE *eTemp);ELEMTYPE queueGetFirst(QUEUEP spQueue);void queueFree(QUEUEP *sppQueue);void main(){QUEUEP spQueue=NULL;int iTemp=0;int iTemp2=0;spQueue=queueInit(10);while(1)if(queueInput(spQueue,iTemp++)==-1)break;printf("%d\n",queueGetFirst(spQueue));while(iTemp2<5)if(queueOutput(spQueue,&iTemp)==1){printf("%d ",iTemp);iTemp2++;}elsebreak;printf("\n");printf("%d\n",queueGetFirst(spQueue));while(1)if(queueInput(spQueue,iTemp2++)==-1)break;while(1)if(queueOutput(spQueue,&iTemp)==1)printf("%d ",iTemp);elsebreak;printf("\n");queueFree(&spQueue);}QUEUEP queueInit(int iSize)//iSize实际节点数{QUEUEP spTemp=NULL;if(iSize<=0)return NULL;spTemp=malloc(STRUCTSIZE);if(!spTemp)return NULL;(*spTemp).epData=malloc(ELEMSIZE*(iSize+1));if(!(*spTemp).epData)return NULL;(*spTemp).iFront=(*spTemp).iRear=0;(*spTemp).iQueueSize=iSize;return spTemp;}STATUS isFull(QUEUEP spQueue)//队满返回1{if( ((*spQueue).iRear+1) % ((*spQueue).iQueueSize+1) == (*spQueue).iFront )return 1;return -1;}STATUS isEmpty(QUEUEP spQueue)//队空返回1{if((*spQueue).iRear==(*spQueue).iFront)return 1;return -1;}STATUS queueInput(QUEUEP spQueue,ELEMTYPE eTemp)//成功返回1{if(isFull(spQueue)==1)return -1;(*spQueue).epData[(*spQueue).iRear]=eTemp;(*spQueue).iRear=((*spQueue).iRear+1)%((*spQueue).iQueueSize+1);return 1;}STATUS queueOutput(QUEUEP spQueue,ELEMTYPE *epTemp)//成功返回1//注意形参{if(isEmpty(spQueue)==1)return -1;*epTemp=(*spQueue).epData[(*spQueue).iFront];(*spQueue).iFront=((*spQueue).iFront+1)%((*spQueue).iQueueSize+1);return 1;}ELEMTYPE queueGetFirst(QUEUEP spQueue)//数据域的类型改变,此函数返回值亦须改变{if(isEmpty(spQueue)==1)return -1;return (*spQueue).epData[(*spQueue).iFront];}void queueFree(QUEUEP *sppQueue)//注意形参{if(!(*sppQueue))return;if((*(*sppQueue)).epData)free((*(*sppQueue)).epData);free(*sppQueue);*sppQueue=NULL;return;}
0 0
- 队列,数组式
- 队列::数组
- 数组队列
- 数组队列
- 队列数组
- 队列数组
- 数组队列
- 队列--数组循环队列
- 数组与数组队列
- 数组与数组队列
- 数组与数组队列
- 数据结构之队列(数组队列)
- 队列----循环数组实现队列
- JAVA实现数组队列,循环数组队列,链式队列
- 队列学习--数组实现
- 队列的数组实现
- python 数组 队列 堆栈
- 数组实现队列
- indexOf() lastIndexOf() 与 jQuery.inArray()
- initWithCoder、awakeFromNib、initWithFrame
- 数据流中的中位数
- Activity 的启动流程分析
- Adapter中函数的调用顺序
- 队列,数组式
- hust——1010F - The Minimum Length(kmp专练)
- java异常处理及400,404,500错误处理
- 游戏中学会写代码:这些编程学习网站不容错过
- Codeforces Round #332 (Div. 2) 的A,B,C,D
- Ubuntu .deb包安装方法
- android学习,通过监听焦点,来进行类似监听软键盘弹出隐藏的功能
- 练习008-009
- 使用<pre></pre> 保留制表符\t 换行符\t\r 格式显示,并强制换行