-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQueue_DataStructure.c
More file actions
77 lines (77 loc) · 1.07 KB
/
Copy pathQueue_DataStructure.c
File metadata and controls
77 lines (77 loc) · 1.07 KB
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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int index=0;
int n=5;
int q[100];
void enqueue(int k)
{
if(index<n)
{
q[index]=k;
index++;
}
else
{
printf("Queue is FULL!!\n");
}
}
void dequeue()
{
if(index==0)
{
printf("Queue is EMPTY!!\n");
}
else
{
int i=1;
printf("The element removed is:%d\n",q[0]);
while(i<index)
{
q[i-1]=q[i];
i++;
}
index--;
}
}
void print()
{
if(index==0)
{
printf("Queue is EMPTY!!\n");
}
else
{
int i=0;
printf("The elements are:\n");
while(i<index)
{
printf("%d\n",q[i]);
i++;
}
}
}
void main()
{
int a,k;
while(1)
{
printf("Select your option:\n");
printf("1.Enqueue\n2.Dequeue\n3.Print elements\n4.Exit\n");
scanf("%d",&a);
switch(a)
{
case 1: printf("Enter the element to be inserted:\n");
scanf("%d",&k);
enqueue(k);
break;
case 2: dequeue();
break;
case 3: print();
break;
case 4: exit(0);
break;
}
}
getch();
}