-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_array.c
More file actions
94 lines (94 loc) · 2.15 KB
/
Copy pathQueue_array.c
File metadata and controls
94 lines (94 loc) · 2.15 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
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
#include<stdio.h>
#include<stdlib.h>
void enque(int);
void deque();
void print();
void display();
int is_full();
int is_empty();
int peek();
int rear = -1,front = -1;
#define SIZE 10
int queue[SIZE];
void main(){
int op,ele;
while(1){
printf("\n* * * * * * * * *\n");
printf("* 1. Enque *\n* 2. Deque *\n* 3. Print *\n* 4. Peek *\n* 5. Is full *\n* 6. Is empty *\n* 7. Exit *\n* 8. Display *\n");
printf("* * * * * * * * *\n\nEnter your option: ");
scanf("%d",&op);
switch (op)
{
case 1: printf("\nEnter element: ");
scanf("%d",&op);
enque(op);
break;
case 2: deque();
break;
case 3: print();
break;
case 4: printf("\nPeek = %d\n",peek());
break;
case 5:
if(is_full())
printf("\nQueue is overlow.\n");
else
printf("\nQueue is not full.\n");
break;
case 6:
if(is_empty())
printf("\nQueue is underlow.\n");
else
printf("\nQueue is not empty.\n");
break;
case 7: exit(1);
break;
case 8: display();
break;
default: printf("\nEnter valid option.\n");
break;
}
}
}
void enque(int in){
if(is_full())
printf("\nQueue is over flow.\n");
else
queue[++rear]=in;
}
void deque(){
if(is_empty())
printf("\nQueue is under flow.\n");
else
printf("\n%d is dequeed.\n",queue[++front]);
}
int is_full(){
if(rear == SIZE-1)
return 1;
else
return 0;
}
int is_empty(){
if(front == rear)
return 1;
else
return 0;
}
void print(){
if(is_empty())
printf("\nQueue is underflow.\n");
else
printf("\nQueue elements are: ");
for(int i=front+1;i<=rear;i++)
printf("%d ",queue[i]);
printf("\n");
}
int peek(){
return queue[rear];
}
void display(){
printf("\nWhole Queue is : ");
for(int i=0;i<SIZE;i++)
printf("%d ",queue[i]);
printf("\n");
}