-
Notifications
You must be signed in to change notification settings - Fork 0
/
QUEUE.BAK
126 lines (121 loc) · 2.26 KB
/
QUEUE.BAK
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<limits.h>
#define CAPACITY 100
int queue[CAPACITY];
unsigned int size = 0;
unsigned int rear = CAPACITY -1;
unsigned int front = 0;
int enqueue(int data);
int dequeue();
int isFull();
int isEmpty();
int getRear();
int getFront();
int main()
{
clrscr();
int ch , data;
while(1)
{
printf("------------\n");
printf(" Queue Array Implementation Program\n");
printf("-------------\n");
printf("1 . Enqueue\n");
printf("2 . dequeue\n");
printf("3 . size\n");
printf("4 . Get Rear\n");
printf("5 . Get Front\n");
printf("6 . Exit\n");
printf("------------\n");
printf("select an option : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Enter data to enqueue : ");
scanf("%d",&data);
if(enqueue (data))
printf("element added into queue ");
else
printf("Queue is Full");
break;
case 2:
data =dequeue();
if(data==INT_MIN)
printf("Queue is Empty");
else
printf("Data => %d",size);
break;
case 3:
if(isEmpty())
printf("Queue is Empty");
else
printf("Queue Size => %d",size);
case 4:
if(isEmpty())
printf("Queue is Empty ");
else
printf("Rear => %d",getRear());
break;
case 5:
if(isEmpty)
printf("Queue is Empty");
else
printf("Front => %d",getFront());
break;
case 6:
printf("Exiting from app.\n");
exit(6);
default:
printf("Invalid choice,Please input number between(1 - 5)");
break;
}
printf("\n\n");
}
}
int enqueue(int data)
{
if(isFull())
{
return 0;
}
rear = ( rear + 1 ) % CAPACITY;
size++;
queue[rear] = data;
return 1;
getch();
}
int dequeue()
{
int data =INT_MIN;
if(isEmpty())
{
return INT_MIN;
}
data= queue[front];
front = ( front + 1 ) % CAPACITY;
size--;
return data;
}
int isFull()
{
return (size = CAPACITY);
}
int isEmpty()
{
return (size=0);
}
int getFront()
{
return(isEmpty())
?INT_MIN
:queue[front];
}
int getRear()
{
return (isEmpty())
?INT_MIN
:queue[rear];
}