队列
2015-11-18 21:17
225 查看
#include<iostream> #include<string.h> #include<ctype.h> #include<malloc.h> #include<limits.h> #include<stdio.h> #include<stdlib.h> //#include<io.h> #include<math.h> //#include<process.h> #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 using namespace std; typedef int QElemType; typedef int Status; typedef struct QNode { QElemType data; QNode *next; }*QueuePtr; struct LinkQueue { QueuePtr front,rear; }; void InitQueue(LinkQueue &Q) { if(!(Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode)))) exit(OVERFLOW); Q.front->next=NULL; } void EnQueue(LinkQueue &Q,QElemType e) { QueuePtr p; if(!(p=(QueuePtr)malloc(sizeof(QNode)))) exit(OVERFLOW); p->data=e; p->next=NULL; Q.rear->next=p; Q.rear=p; } Status DeQueue(LinkQueue &Q,QElemType &e) { QueuePtr p; if(Q.front==Q.rear) return ERROR; p=Q.front->next; e=p->data; Q.front->next=p->next; if(Q.rear==p) Q.rear=Q.front; free(p); return OK; } int main() { int i; QElemType d; LinkQueue q; InitQueue(q); while(scanf("%d",&i)!=EOF) { EnQueue(q,i); } while(q.front!=q.rear) {DeQueue(q,d); printf("%d",d);} }
相关文章推荐
- 富士康为什么钟情河南?
- CocoaChina上各种开发专题的丰富例子
- stm32启动文件
- json常用的方法总结
- Swift_Singleton
- Swift_UIImageView
- c语言之康托展开
- 【结果很简单,过程很艰辛】记阿里云Ons消息队列服务填坑过程
- leetcode 59:Spiral Matrix II
- 做了一个用友导出excel转为金三导入excel的软件
- iOS开发——UI组件
- 基于Spark Streaming的僵尸主机检测算法
- Swift_UIButton
- 关于STM32的ISP指令
- 野鸟装备如何支持表情的
- 时间管理
- RabbitMQ基础概念详细介绍
- Swift_UITextField
- poj 2125 Destroying The Graph 最小点权覆盖集
- jsp下载文件的实现方法