循环队列的链式存储结构

 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 }
原文地址:https://www.cnblogs.com/crazycodehzp/p/3541811.html