- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-queue.c
More file actions
Latest commit
65 lines (53 loc) · 1.06 KB
/
Copy patharray-queue.c
File metadata and controls
65 lines (53 loc) · 1.06 KB
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
//1.array queue
// 数组队列
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#defineQUEUE_SIZE 10
structqueue {
unsigned intarray[QUEUE_SIZE];
intcount;
};
voidqueue_init(structqueue*q)
{
q->count=0;
}
intqueue_empty(structqueue*q)
{
return (q->count==0);
}
intqueue_full(structqueue*q)
{
return (q->count==QUEUE_SIZE);
}
intenqueue(structqueue*q, intvalue)
{
if (queue_full(q))
return-1;
q->array[q->count++] =value;
return0;
}
intdequeue(structqueue*q)
{
if (queue_empty(q))
return-1;
returnq->array[--q->count];
}
/**************test sample*******************/
intmain(intargc, char*argv[])
{
structqueuequeue;
queue_init(&queue);
enqueue(&queue, 1);
enqueue(&queue, 2);
enqueue(&queue, 3);
enqueue(&queue, 4);
enqueue(&queue, 5);
printf("dequeue:%d\n", dequeue(&queue));
printf("dequeue:%d\n", dequeue(&queue));
printf("dequeue:%d\n", dequeue(&queue));
printf("dequeue:%d\n", dequeue(&queue));
printf("dequeue:%d\n", dequeue(&queue));
printf("dequeue:%d\n", dequeue(&queue));
return0;
}