forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinear Queue
134 lines (115 loc) · 1.64 KB
/
Linear Queue
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
127
128
129
130
131
132
133
134
#include<stdio.h>
#include<stdlib.h>
#define SIZE 5
int queue[SIZE];
int front=0;
int rear=0;
void enqueue();
void dequeue();
void size();
void display();
void front_ele();
void rear_ele();
int Isfull();
int Isempty();
void main()
{ int ch;
while(1)
{ printf("\n Operations on static Queue : \n");
printf("1. Enqueue(Max 5) \n 2. Dequeue \n 3. Size \n 4. Display \n 5.Front_Value \n 6.Rear_Value \n 7.Exit \n");
scanf("%d",&ch);
switch(ch)
{case 1: enqueue();
break;
case 2:dequeue();
break;
case 3:size();
break;
case 4:display();
break;
case 5: front_ele();
break;
case 6: rear_ele();
break;
case 7:exit(0);
break;
default: printf("Invalid choice\n");
}
}
}
void enqueue()
{ if(Isfull())
{
printf("Queue Overflow\n");
}
else
{int ele;
printf("Enter Element: ");
scanf("%d",&ele);
queue[rear++]=ele;
}
}
int Isfull()
{
if(rear==SIZE)
return 1;
else
return 0;
}
void dequeue()
{if(Isempty())
{
printf("Queue Underflow\n");
}
else
{int i;
for(i=front;i<rear;i++)
{ queue[i]=queue[i+1];
}
rear--;
}
}
int Isempty()
{ if(front==rear)
return 1;
else
return 0;
}
void size()
{ int count=rear+1;
printf("Size of queue: %d",count);
}
void display()
{int i;
if(Isempty())
{
printf("Queue is empty\n");
}
else
{printf("Elements : ");
for(i=front;i<rear;i++)
{
printf("%d ",queue[i]);
}
}
}
void front_ele()
{ if(Isempty())
{
printf("Queue is empty\n");
}
else
{
printf(" Front Element: %d ",queue[front]);
}
}
void rear_ele()
{if(Isempty())
{
printf("Queue is empty\n");
}
else
{
printf(" Rear Element: %d ",queue[rear]);
}
}