forked from 11-yashasvi/Basic_Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQUEUE_using_Structure.c
93 lines (92 loc) · 1.86 KB
/
QUEUE_using_Structure.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
/*Queue using Structure*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX 50
struct queue
{
int queue_arr[MAX];
int rear;
int front;
};
typedef struct queue node;
void insert(node *q)
{
int added_item;
if (q->rear == MAX - 1)
{
printf("\nQueue Overflow\n");
getch();
}
else
{
if (q->front == -1)
q->front = 0;
printf("\nInput the element for adding in queue:");
scanf("%d", &added_item);
q->rear = q->rear + 1;
q->queue_arr[q->rear] = added_item;
}
}
void del(node *q)
{
if (q->front == -1 || q->front > q->rear)
{
printf("\nQueue Underflow\n");
}
else
{
printf("\nElement deleted from queue is : %d\n", q->queue_arr[q->front]);
q->front = q->front + 1;
}
}
void display(node *q)
{
int i;
if (q->front == -1 || q->front > q->rear)
{
printf("\nQueue is empty\n");
}
else
{
printf("\nQueue is :\n");
for (i = q->front; i <= q->rear; i++)
printf("%d ", q->queue_arr[i]);
printf("\n");
}
}
void main()
{
int choice;
struct queue *r;
r->rear = -1;
r->front = -1;
while (1)
{
//clrscr();
printf("\n1.Insert\n");
printf("2.Delete\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("\nEnter your choice:");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert(r);
break;
case 2:
del(r);
getch();
break;
case 3:
display(r);
getch();
break;
case 4:
exit(0);
default:
printf("\n Wrong choice\n");
}
}
}