-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.c
70 lines (54 loc) · 1.01 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
#include "queue.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
void init_queue(pqueue que)
{
assert( que != NULL);
if( que == 0) return ;
que->count = 0;
que->head = (CirList)malloc( sizeof(CNode));
init_cir(que->head);
}
void destroy_queue(pqueue que)
{
assert( que != NULL);
if( que == 0) return ;
que->count = 0;
clear_cir(que->head);
que->head = NULL;
}
void clear_queue(pqueue que)
{
assert( que != NULL);
if( que == 0) return ;
que->count = 0;
clear_cir(que->head);
}
int queue_length(pqueue que)
{
assert( que != NULL);
if( que == 0) return ;
return que->count;
}
ElemType gethead_queue(pqueue que)
{
ElemType out;
assert( que != NULL);
if( que == NULL) return out;
return find_cir_pos( que->head, 0);
}
void push_queue(pqueue que, ElemType val)
{
assert( que != NULL);
if( que == NULL) return ;
insert_cir_tail(que->head, val);
que->count++;
}
void pop_queue(pqueue que)
{
assert( que != NULL);
if( que == NULL) return ;
delete_cir_head(que->head);
que->count--;
}