Repository navigation
Expand file tree
/
Copy pathllimplementofqueue
More file actions
104 lines (94 loc) · 1.69 KB
/
Copy pathllimplementofqueue
File metadata and controls
104 lines (94 loc) · 1.69 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
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
#include <stdio.h>
#include <stdlib.h>
struct Node *f = NULL;
struct Node *r = NULL;
struct Node
{
int data;
struct Node *next;
};
void enqueue(int data)
{
struct Node *new;
new = malloc(sizeof(struct Node));
// memory main new node banni but abhi new node empty hai
if (new == NULL)
{
printf("Overflow\n");
exit(1);
}
new->data = data;
new->next = NULL;
// f and r null queue empty
if (f == NULL)
{
f = r = new;
}
else
{
r->next = new;
r = new;
}
}
int dequeue()
{
// temporary pointer created
struct Node *temp;
temp = f;
if (f == NULL)
{
printf("queue empty\n");
exit(1);
}
int value = temp->data;
f = f->next;
free(temp);
temp = NULL;
return value;
}
void print()
{
struct Node *temp;
temp = f;
// if (isEmpty())
// {
// printf("Stack Underflow\n");
// exit(1);
// }
while (temp)
{
printf("%d ", temp->data);
temp = temp->next;
}
}
int main()
{
int choice, data, res;
do
{
printf("\n 1 insertion\n");
printf("2 deletion\n");
printf("3 display\n");
printf("4 exit\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
scanf(" %d", &data);
printf("inserted %d\n", data);
enqueue(data);
break;
case 2:
printf("deletion \n");
res = dequeue();
printf("%d ", res);
break;
case 3:
print();
break;
case 4:
break;
}
} while (choice != 4);
return 0;
}