forked from TusharKukra/Hacktoberfest2021-EXCLUDED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.c
97 lines (93 loc) · 1.47 KB
/
Queue.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
97
/* Program for implementation of simple queue */
#include<stdio.h>
#include<conio.h>
#define MAXSIZE 5
int que[5];
int front=-1,rear=-1;
int choice;
char ch;
int item;
void insert();
void del();
void traverse();
void main()
{
do{
clrscr();
printf("\n 1-Insert");
printf("\n 2-Delete");
printf("\n 3-Traverse");
printf("\n Enter your choice::");
scanf("%d",&choice);
switch(choice)
{
case 1:insert();
break;
case 2:del();
break;
case 3:traverse();
break;
default:printf("Invalid choice");
}
printf("\n Do u wish to continue...");
fflush(stdin);
scanf("%c",&ch);
}while(ch == 'y'||ch == 'Y');
getch();
}
void insert()
{
if(rear==MAXSIZE-1)
{
printf("Queue Overflow");
return;
}
else
{
printf("\nEnter a value to insert:: ");
scanf("%d",&item);
if(front==-1)
front=rear=0;
else
rear=rear+1;
que[rear]=item;
}
return;
}
void del()
{
if(front==-1)
{
printf("\nqueue is empty");
return;
}
else
{
item=que[front];
}
if(front==rear)
{
front=rear=-1;
}
else
{
front=front+1;
}
printf("\n The deleted value is %d",item);
}
void traverse()
{
int i;
if(front<0)
{
printf("\nqueue is empty");
return;
}
else
{
for(i=front;i<=rear;i++)
{
printf("\n%d",que[i]);
}
}
}