-
Notifications
You must be signed in to change notification settings - Fork 0
/
dslab6.c
66 lines (57 loc) · 1.12 KB
/
dslab6.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
//Cricular Queue
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int item,q[20],i,rear=-1,front=0,count=0;
void insert(){
if(count == SIZE ){
printf("Circular Queue Overflow.\n");
return;
}
printf("Enter item to insert:\n");
scanf("%d",&item);
rear = (rear+1)%SIZE;
q[rear] = item;
count++;
}
void delete(){
if(count == 0){
printf("Queue Underflow.\n");
return;
}
item = q[front];
front = (front+1)%SIZE;
count--;
printf("The Deleted Item is: %d\n",item);
}
void display(){
int f;
if(count == 0){
printf("The Queue is empty.\n");
return;
}
printf("The Content of the Queue are:\n");
f = front;
for(i=0;i<=rear;i++){
printf("%d\t",q[f]);
f = (f+1)%SIZE;
}
printf("\n");
}
int main(){
int ch;
while(1){
printf("\t MENU\n");
printf("1. insert \n 2. Delete \n 3. display \n 4. exit \n");
printf("Enter your choice:\n");
scanf("%d",&ch);
switch(ch){
case 1: insert(); break;
case 2: delete(); break;
case 3: display(); break;
case 4: exit(0);
default:printf("Enter valid choice:\n");
}
}
return 0;
}