链队列-数据结构(11)
来源:互联网 发布:指甲油品牌推荐知乎 编辑:程序博客网 时间:2024/06/15 12:39
一、解析
对于链队列,队列的意义就不解析了。而队列的链式存储则是与顺序队列成为一个很好的对比,顺序队列中的存储大小是固定的不,而链式的存储则是可以达到节省存储空间的作用,只是在入队和出队的情况下,需要些额外的操作。参考书上P60-P63。
二、存储结构
//==================链队列===============typedef struct QNode{QElemType data;struct QNode *next;}QNode, *QueuePtr;typedef struct{QueuePtr front;//队头QueuePtr rear;//队尾}LinkQueue;
三、操作
//==================链队列===============typedef struct QNode{QElemType data;struct QNode *next;}QNode, *QueuePtr;typedef struct{QueuePtr front;//队头QueuePtr rear;//队尾}LinkQueue;Status InitQueue(LinkQueue &Q){//构造一个空队列QQ.front = (QueuePtr)malloc(sizeof(QNode));Q.rear = Q.front;if (!Q.front){return OVERFLOW;}Q.front->next = NULL;return OK;}Status EnQueue(LinkQueue &Q, QElemType e){//进队列 在队尾入队QueuePtr p = (QueuePtr)malloc(sizeof(QNode));p->data = e;p->next = NULL;Q.rear->next = p;Q.rear = p;return OK;}Status DeQueue(LinkQueue &Q, QElemType &e){//出队列if (Q.front == Q.rear){printf("队列为null");return ERROR;}//Q.front = Q.front->next;QueuePtr p = Q.front->next;e = p->data;Q.front->next = p->next;if (Q.rear == p){Q.rear = Q.front;}free(p);return OK;}
四、执行
LinkQueue q;InitQueue(q);EnQueue(q,1);EnQueue(q, 2);EnQueue(q, 3);EnQueue(q, 4);int e;DeQueue(q, e);printf("%d\n",e);DeQueue(q, e);printf("%d\n", e);DeQueue(q, e);printf("%d\n", e);DeQueue(q, e);printf("%d\n", e);DeQueue(q, e);printf("%d\n", e);
输出:
1234队列为null4请按任意键继续. . .
阅读全文
0 0
- 链队列-数据结构(11)
- 数据结构之链队列
- 数据结构链队列算法
- 数据结构链表队列
- 数据结构-链表队列
- 数据结构----链表队列
- 【数据结构】链队列_LinkQueue
- 数据结构之链队列
- 数据结构之链队列
- 数据结构之链队列
- 数据结构-链队列
- 数据结构之链队列
- 数据结构之链队列
- 数据结构_链队列
- 数据结构6链队列
- 数据结构:链表队列
- 数据结构之链队列
- 数据结构--链队列
- 【HTTP】Fiddler
- Codeforces Round #277.5 (Div. 2)-F. Special Matrices
- android ImageView-在界面中显示图片
- Android 7.0之访问文件的权限和FileProvider类
- Android中图片的三级缓存(非常详细)
- 链队列-数据结构(11)
- HttpPost忽略证书请求https
- <spring:message />国际化
- BZOJ4886 [Lydsy2017年5月月赛]叠塔游戏
- getprop命令
- Android Audio Focus的应用(requestAudioFocus)
- dp四边形优化 Hdu 3480 Division 题解
- 认识Button 和 ImageButton
- 职场女性