队列 —— 链队列
来源:互联网 发布:云数据财富平台 编辑:程序博客网 时间:2024/06/14 18:29
队列
代码
/* function:queue created by : xilong date: 2017.2.9*/#include "iostream"using namespace std;#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0typedef int Elemtype;typedef int Status;typedef struct QNode{ Elemtype data; struct QNode* next;} QNode, *QueuePrt;typedef struct{ QueuePrt front, rear;} LinkQueue;/* initialize the queue*/Status Init_Queue(LinkQueue *q){ q->front = q->rear = (QueuePrt)malloc(sizeof(QNode)); if (!q->front) exit(0); q->front->next = NULL; return OK;}/* Insert an element into the queue, an element can only be inserted into the end of the queue */Status Inster_Queue(LinkQueue *q, Elemtype e){ QueuePrt p; p = (QueuePrt)malloc(sizeof(QNode)); if (p == NULL) exit(0); p->data = e; p->next = NULL; q->rear->next = p; q->rear = p; return OK;}/* Delete an element in the queue, an element which is in the front can only be deleted */Status Delete_Queue(LinkQueue *q, Elemtype *e){ QueuePrt p; if (q->front == q->rear) { cout << "空队!" << endl; return FALSE; } p = q->front->next; q->front->next = p->next; if (q->rear == p) { q->rear = q->front; } *e = p->data; free(p); return TRUE;}/* length of the queue*/int Length_Queue(LinkQueue *q){ QueuePrt p; int len = 0; p = q->front->next; if (q->front == q->rear) cout << "空队!" << endl; while (p) { len++; p = p->next; } return len;}void main(){ LinkQueue q; Elemtype e; int i, len; Init_Queue(&q); Inster_Queue(&q, 1); Inster_Queue(&q, 2); Inster_Queue(&q, 3); Inster_Queue(&q, 4); Inster_Queue(&q, 5); Inster_Queue(&q, 6); Inster_Queue(&q, 7); Inster_Queue(&q, 8); len = Length_Queue(&q); cout << "队列的长度为:"; cout << len << endl; cout << "出对列的顺序为:"; for (i = 0; i < len; i++) { Delete_Queue(&q, &e); cout << e << " "; } cout << endl; system("pause");}
截图
0 0
- 队列 —— 链队列
- 队列——链队列
- 队列——顺序队列
- 队列-循环队列/链队列
- 队列,链队列,循环队列
- 队列,链队列,循环队列
- 队列第二篇————链队列
- 链队列——队列的链式表示与实现
- 链队列——队列的链式表示和实现
- 单链队列——队列的链式存储结构
- 实验3.4 栈与队列——链队列
- 数据结构——链队列
- 数据结构——链队列
- 数据结构——栈与队列(顺序栈、链栈、循环队列、链队列)
- 数据结构——队列之顺序队列
- 数据结构——队列及循环队列
- 队列--链表队列
- 队列之链队列
- 关于shell脚本变量的一些知识
- WPF 将文本框 改为水印文本框 支持密码输入
- Taglib自定义标签之三简单仿JSTL中带标签体的ForEach循环
- 杭电1420 Prepared for New Acmer
- php的冒泡排序和快速排序
- 队列 —— 链队列
- java中public,private,protected,(default)关键字
- Java设计模式之行为型模式(策略模式)
- 内置存储fuse文件系统
- 数据结构与算法学习
- [BZOJ3640]JC的小苹果(概率dp+高斯消元)
- 3_MyEclipse 快捷键
- Taglib自定义标签之四自定义标签中的Function函数
- ArtifactTransferException: Failure to transfer org.apache.openejb:javaee-api:jar:5.0-1