首页 > 其他 > 详细

循环队列的链式存储结构

时间:2014-02-09 22:00:30      阅读:485      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 #include "stdafx.h"
 2 #include <iostream>
 3 #include <exception>
 4 using namespace std;
 5 
 6 //循环队列的顺序存储结构
 7 
 8 typedef int Status;
 9 const int ok = 1;
10 const int error = 0;
11 const int maxSize = 5;
12 
13 typedef int QElemType;
14 
15 typedef struct QNode
16 {
17     QElemType data;
18     struct QNode *next;
19 }QNode,*QueuePtr;
20 
21 typedef struct 
22 {
23     QueuePtr front,rear;
24 }LinkQueue;
25 
26 Status EnQueue(LinkQueue *Q,const QElemType e)
27 {
28     QueuePtr p = (QueuePtr)malloc(sizeof(QNode));
29     if(!p)
30         exit(OVERFLOW);
31     p->data=e;
32     p->next = NULL;
33     Q->rear->next=p;
34     Q->rear=p;
35     return ok;
36 }
37 Status DeQueue(LinkQueue *Q)
38 {
39     if(Q->front==Q->rear)
40         return error;
41     QueuePtr p;
42     p=Q->front->next;
43     cout<<p->data<<endl;
44     Q->front->next = p -> next;
45     if(Q->rear == p)
46         Q->rear = Q->front;
47     free(p);
48     return ok;
49 }
50 int _tmain(int argc, _TCHAR* argv[])
51 {
52 
53     return 0 ;
54 }
bubuko.com,布布扣

循环队列的链式存储结构

原文:http://www.cnblogs.com/crazycodehzp/p/3541811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!