-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcqusingarray.c
More file actions
71 lines (66 loc) · 1.45 KB
/
cqusingarray.c
File metadata and controls
71 lines (66 loc) · 1.45 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
#include<stdio.h>
#define max 5
int arr[max], rear = -1, front = -1;
void Add(){
if((rear+1)%max == front){
printf("Queue is Full");
}
else{
rear++;
rear%=max;
printf("Enter element:");
scanf("%d",&arr[rear]);
}
if(front == -1) front = 0;
}
void Remove(){
if(front == -1 || (front+1)%max == rear){
printf("Queue is empty");
}
else{
printf("Removed item is :%d\n",arr[front]);
front++;
front%=max;
}
}
void Display(){
if(front == -1 || (front+1)%max == rear){
printf("Queue is empty");
}
else if (rear>front)
{
for(int i=front;i<=rear;i++){
printf("%d ",arr[i] );
}printf("\n");
}
else{
for(int i=front;i<max;i++){
printf("%d ",arr[i]);
}
for(int i=0;i<=rear;i++){
printf("%d ",arr[i]);
}printf("\n");
}
}
int main(){
printf("Enter Option:\n");
printf("1.Add\n2.Remove\n3.Display\n4.Exit\n");
int f;
while(1){
printf("Enter Choice:");
scanf("%d",&f);
switch(f){
case 1:
Add();
break;
case 2:
Remove();
break;
case 3:
Display();
break;
case 4:
return 0;
}
}
}