-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbo3-3.cpp
55 lines (46 loc) · 1015 Bytes
/
bo3-3.cpp
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
// bo3-3.cpp 用单链表的基本操作实现链队列(存储结构由c3-2.h定义)的基本操作(9个)
typedef QElemType ElemType;
#define LinkList QueuePtr
#define LNode QNode
#include"bo2-2.cpp"
void InitQueue(LinkQueue &Q)
{
InitList(Q.front);
Q.rear=Q.front;
}
void DestroyQueue(LinkQueue &Q)
{
DestroyList(Q.front);
Q.rear=Q.front;
}
void ClearQueue(LinkQueue &Q)
{
ClearList(Q.front);
Q.rear=Q.front;
}
Status QueueEmpty(LinkQueue Q)
{
return ListEmpty(Q.front);
}
int QueueLength(LinkQueue Q)
{
return ListLength(Q.front);
}
Status GetHead(LinkQueue Q,QElemType &e)
{
return GetElem(Q.front,1,e);
}
void EnQueue(LinkQueue &Q,QElemType e)
{
ListInsert(Q.front,ListLength(Q.front)+1,e);
}
Status DeQueue(LinkQueue &Q,QElemType &e)
{
if(Q.front->next==Q.rear)
Q.rear=Q.front;
return ListDelete(Q.front,1,e);
}
void QueueTraverse(LinkQueue Q,void(*visit)(QElemType))
{
ListTraverse(Q.front,visit);
}