forked from seeditsolution/cprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcircle.c
96 lines (96 loc) · 1.53 KB
/
qcircle.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<stdio.h>
#define max 10
int queue[max];
int front, rear;
void createQueue()
{
front = rear = -1;
}
void insert()
{
int num;
printf("Please enter the number to be inserted :\n");
scanf("%d", &num);
if((front==0 && rear==max-1) || (front == rear+1))
printf("Queue is FULL\n");
else
{
if((front == -1) && (rear == -1))
front = rear = 0;
else if((rear == max-1) && (front != -1))
rear = 0;
else
rear++;
queue[rear] = num;
}
}
void DELETE()
{
if((front == -1) && (rear == -1))
printf("Queue is EMPTY\n");
else
{
printf("The deleted element is %d\n", queue[front]);
if(front == rear)
front = rear = -1;
else if(front == max-1)
{
front = 0;
}
else
front++;
}
}
void peek()
{
if((front == -1) && (rear == -1))
printf("Queue is EMPTY\n");
else
printf("The element at the top is %d\n", queue[front]);
}
void display()
{
int i;
if((front == -1) && (rear == -1))
printf("Queue is EMPTY\n");
else if(front < rear)
{
for(i=front; i<=rear; i++)
printf("%d\t", queue[i]);
printf("\n");
}
else
{
for(i=front; i<=(max-1); i++)
printf("%d\t", queue[i]);
for(i=0; i<=rear; i++)
printf("%d\t", queue[i]);
printf("\n");
}
}
void main()
{
createQueue();
int ch;
do
{
printf("\nPlease enter the choice\n");
printf("1: INSERT\n2: DELETE\n3: PEEK\n4: DISPALY\n5: QUIT\n");
scanf("%d", &ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
DELETE();
break;
case 3:
peek();
break;
case 4:
display();
break;
}
}while(ch != 5);
}