forked from JohnHau/mis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loopq.c
executable file
·136 lines (86 loc) · 1.53 KB
/
loopq.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct _queue
{
uint32_t head;
uint32_t tail;
uint32_t* buf;
}Queue;
#define qSize 8
Queue qa;
uint32_t myBuffer[qSize+1]={0};
int32_t initQueue(Queue *q,uint32_t *buffer)
{
q->head =0;
q->tail = q->head;
q->buf=buffer;
return 0;
}
int32_t enQueue(Queue*q,uint32_t n)
{
if((q->tail +1)%(qSize+1) == q->head)
{
printf("The queue has been full!\n");
return -1;
}
q->buf[q->tail] = n;
q->tail = (q->tail +1)%(qSize+1);
return 0;
}
int32_t deQueue(Queue*q,uint32_t *val)
{
if(q->tail == q->head)
{
printf("The Queue has been empty\n");
return -1;
}
*val = q->buf[q->head];
q->head= (q->head +1)%(qSize+1);
return 0;
}
int32_t compareArray(uint32_t *sArray,uint32_t *dArray,uint32_t len)
{
uint32_t i;
for(i=0;i<len;i++)
{
if(sArray[i] != dArray[i])
{
return -1;
}
}
return 1;
}
uint32_t enlist[qSize]={0};
uint32_t delist[qSize]={0};
int main(int argc ,char*argv[])
{
int32_t rv=0;
int32_t i=0;
srand(time(NULL));
uint32_t vlist[16]={0};
initQueue(&qa,myBuffer);
for(i=0;i<qSize;i++)
{
vlist[i] = rand()%0xffff;
}
for(i=0;i<qSize;i++)
{
enQueue(&qa,enlist[i]);
}
for(i=0;i<qSize;i++)
{
deQueue(&qa,&delist[i]);
}
if(compareArray(enlist,delist,qSize) ==1)
{
printf("success\n");
return 0;
}
else
{
printf("error\n");
return -1;
}
return 0;
}