-
Notifications
You must be signed in to change notification settings - Fork 0
/
q04.c
47 lines (43 loc) · 915 Bytes
/
q04.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
/*
/*
/* Design, develop, and execute a program in C to simulate the
/* working of a queue of integers using an array. Provide the following
/* operations:
/* a. Insert b. Delete c. Display
/*
*/
#include <stdio.h>
#define MAX 100
void main() {
int queue[MAX], front = -1, rear = -1;
printf(" \n Enter \n");
printf(" i to Insert\n");
printf(" d to Delete\n");
printf(" s to Show\n");
do {
int item;
char choice;
printf(">> ");
scanf("%c", &choice);
switch(choice) {
case 'i':
printf(" Enter value to insert: ");
scanf("%d", &item);
if(rear != MAX - 1)
queue[++rear] = item;
break;
case 'd':
if(front != rear)
printf(" Deleted: %d\n", queue[++front]);
break;
case 's':
for(item = front + 1; item <= rear; item++)
printf(" %d", queue[item]);
printf("\n");
break;
default:
return;
}
scanf("%c", &choice);
} while(1);
}