-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.c
57 lines (51 loc) · 1011 Bytes
/
Queue.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <Queue.h>
//初始化链队列
Status InitQueue(LinkQueue Q){
Q.front = Q.rear = (QNode *)malloc(sizeof(QNode));
if(!Q.front){
exit(OVERFLOW);
}
Q.front = Q.rear = NULL;
return OK;
}
//销毁链队列
Status DestoryQueue(LinkQueue Q){
while(Q.front){
Q.rear = (QNode*)Q.front->next;
free(Q.front);
Q.front = Q.rear;
}
return ERROR;
}
//插入队列
Status EnQueue(LinkQueue *Q,QElemType e){
QNode *p = (QNode *)malloc(sizeof(QNode));
if(!p){
return OVERFLOW;
}
p->data = e;
p->next = NULL;
(QNode*)Q->rear->next = p;
Q->rear = p;
return OK;
}
//删除元素
Status DeQueue(LinkQueue *Q,QElemType e){
//判断碎裂是不是为空
if(Q->front == Q->rear){
return ERROR;
}
QNode *p = (QNode*)Q->front->next;
e = p->data;
Q->front->next = p->next;
if(Q->rear==p){
Q->rear = Q->front;
}
free(p);
}
int main(){
//
return 0;
}