-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQueue Array.C
More file actions
60 lines (60 loc) · 1.09 KB
/
Queue Array.C
File metadata and controls
60 lines (60 loc) · 1.09 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
#include<stdio.h>
#include<conio.h>
void enqueue(int arr[],int item, int *rear){
if(*rear>20)
printf("Overflow");
else{
*rear+=1;
arr[*rear]=item;
}
}
void dequeue(int arr[],int *rear){
int i;
if(*rear>-1){
for(i=0;i<*rear;i++)
arr[i]=arr[i+1];
*rear-=1;
}
else
printf("Underflow!!");
}
void disp(int arr[],int rear){
int i;
printf("Queue is: \n\t|");
for(i=0;i<=rear;i++)
printf(" %d |",arr[i]);
}
void main()
{
int arr[20],i,cho,rear=-1,item;
do{
clrscr();
printf("\n\t\t-----Queue Menu___ ");
printf("\n\t\t\t1.Enqueue");
printf("\n\t\t\t2.Dequeue");
printf("\n\t\t\t3.Display");
printf("\n\t\t\t4.Exit");
printf("\n\t\t\tEnter your choice: ");
scanf("%d",&cho);
switch(cho){
case 1: clrscr();
printf("Enter the item to add: ");
scanf("%d",&item);
enqueue(arr,item,&rear);
disp(arr,rear);
getch();
break;
case 2: clrscr();
dequeue(arr,&rear);
disp(arr,rear);
getch();
break;
case 3:
clrscr();
disp(arr,rear);
getch();
break;
case 4:exit(0);
}
}while(cho!=4);
}