-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.c
77 lines (68 loc) · 1.31 KB
/
Queue.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
#include <stdio.h>
#include <stdlib.h>
int size;
struct Queue
{
int arr[100];
int rear ;
int front;
}qu;
int main(){
qu.front=0;
qu.rear=-1;
printf("Please Input Queue size : ");
scanf("%d",&size);
int ch,element;
do{
printf("\nEnter Your Choice: (1 for EnQueue 2 for DeQueue 3 for Display 4 for Exit:)");
scanf("%d",&ch);
switch(ch){
case 1:{
printf("Enter the Value : ");
scanf("%d",&element);
enQueue(element);
break;
}
case 2:{
deQueue();
break;
}
case 3:{
display();
break;
}
case 4:{
break;
}
}
}while(ch!=4);
}
void enQueue(int ele,int n){
if(qu.rear==(size-1)){
printf("Queue Overflow\n");
}
else{
qu.rear++;
qu.arr[qu.rear]=ele;
}
}
int deQueue(){
int out;
if (qu.front == - 1 || qu.front > qu.rear)
{
printf("Queue Underflow \n");
return 0;
}
else{
out=qu.arr[qu.front];
qu.front--;
return out;
}
}
void display(){
if (qu.front == - 1)
printf("Queue is empty \n");
for(int i=qu.front;i<=qu.rear;i++){
printf("%d\t",qu.arr[i]);
}
}