-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ2.txt
60 lines (56 loc) · 1.11 KB
/
Q2.txt
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
#include <stdio.h>
#include <stdlib.h>
#include "Node.h"
#define MAX_QUEUE 5
#define true 1
#define false 0
typedef int boolean;
int items[MAX_QUEUE];
int front = 0;
int back = MAX_QUEUE-1;
int count = 0;
boolean isEmpty(){
if((count == 0)&&(front == back))
return true;
else return false;
}
boolean isFull(){
if(count == MAX_QUEUE)
return true;
else return false;
}
boolean enqueue(int newItem){
if (!isFull()){
back = (back+1) % MAX_QUEUE;
items[back] = newItem;
++count;
return true;
} else return false;
}
int dequeue(){
if(isEmpty() == false){
int queueFront = items[front];
front = (front+1) % MAX_QUEUE;
count--;
return queueFront;
} else return -1;
}
void dequeueAll(){
front = 0;
back = MAX_QUEUE-1;
count = 0;
}
int peek(){
if(isEmpty() == false){
return items[front];
} else return -1;
}
void main(){
int i;
for (i=0; i>1; i++){
enqueue(i);
}
while(isEmpty() == false){
printf("%d\t",dequeue());
}
}