-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqQueue.c
79 lines (71 loc) · 1.42 KB
/
SqQueue.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* =====================================================================================
*
* Filename: SqQueue.c
*
* Description:
*
* Version: 1.0
* Created: 11%30%2014 10:57:30 AM
* Revision: none
* Compiler: gcc
*
* Author: 张世龙 (mn), [email protected]
* Company: free
*
* =====================================================================================
*/
#include "Public.h"
#include "SqQueue.h"
void InitQueue(SqQueue *queue)
{
assert(queue);
queue->front = 0;
queue->rear = 0;
}
void DestoryQueue(SqQueue *queue)
{
assert(queue);
queue->front = 0;
queue->rear = 0;
}
void ClearQueue(SqQueue *queue)
{
assert(queue);
queue->front = 0;
queue->rear = 0;
}
int QueueEmpty(SqQueue *queue)
{
assert(queue);
return QueueLength(queue)==0;
}
int GetHead(SqQueue *queue,ElemType *e)
{
assert(queue || e);
if(QueueEmpty(queue))
return ERROR;
*e = queue->data[queue->front];
return SUCCESS;
}
int EnQueue(SqQueue *queue,ElemType *e)
{
assert(queue || e);
if((queue->rear+1)%MAXSIZE == queue->front)//队满
return ERROR;
queue->data[queue->rear++] = *e;
return SUCCESS;
}
int DeQueue(SqQueue *queue,ElemType *e)
{
assert(queue || e);
if(QueueLength(queue) == 0)
return ERROR;
*e = queue->data[queue->front++];
return SUCCESS;
}
int QueueLength(SqQueue *queue)
{
assert(queue);
return (queue->rear-queue->front+MAXSIZE)%MAXSIZE;
}