-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotatingQueue.c
executable file
·60 lines (52 loc) · 1.21 KB
/
RotatingQueue.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
#include <includes.h>
#include <stdlib.h>
#include <stdio.h>
#include "RotatingQueue.h"
#define SIZE 50
int internalstack[SIZE];
int nextEmpty = 0, bottomOfStack = 0, numberOfElements = 0;
//int i = 0;
void push(int i) {
if (isFull()!=1) {
internalstack[nextEmpty]= i;
nextEmpty++;
nextEmpty = nextEmpty%SIZE;
numberOfElements++;
}else{
// printf("FULL\n");
}
}
int pop(void) {
if (isEmpty() == 1) {
return -1;
} else {
bottomOfStack++;
bottomOfStack = bottomOfStack%SIZE;
numberOfElements--;
if (bottomOfStack-1 == -1)
bottomOfStack=SIZE;
return internalstack[bottomOfStack-1];
}
}
int peek(void) {
return internalstack[bottomOfStack];
}
int isEmpty(void) {
return numberOfElements == 0 ? 1 : 0;
}
int isFull(void) {
return numberOfElements == SIZE ? 1 : 0;
}
void clearQueue(void) {
nextEmpty = 0;
bottomOfStack = 0;
for (numberOfElements = 0; numberOfElements < SIZE; numberOfElements++) {
internalstack[numberOfElements] = 0;
}
numberOfElements = 0;
}
//void displayQueue(void){
// for (i=0; i<SIZE; i++) {
// printf("%i\n",internalstack[i]);
// }
//}