-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinkque.c
76 lines (71 loc) · 1.41 KB
/
linkque.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
#include <stdio.h>
#include <stdlib.h>
struct Node *f = NULL;
struct Node *r = NULL;
struct Node
{
int data;
struct Node *next;
};
void print(struct Node *ptr)
{
while (ptr != NULL)
{
printf("Element: %d\n", ptr->data);
ptr = ptr->next;
}
}
void enque(int val)
{
struct Node *n = (struct Node *)malloc(sizeof(struct Node));
if (n == NULL)
printf("Queue is Full");
else
n->data = val;
n->next = NULL;
if (f == NULL)
f = r = n;
else
r->next = n;
r = n;
printf("Enqueue Element is : %d\n", val);
}
int deque()
{
int val = -1;
struct Node *ptr = f;
if (f == NULL)
printf("Queue is Empty\n");
else
f = f->next;
val = ptr->data;
free(ptr);
printf("Dequeue Element is : %d\n", val);
}
int main()
{
int q;
int n, m, remove;
printf("Enter Size : ");
scanf("%d", &n);
printf("Enter Enqueue Element : ");
for (int i = 0; i < n; i++)
{
scanf("%d", &m);
enque(m);
}
printf("Do you want to Dqueue (1/n) : ");
scanf("%d",&q);
if (q == 1){
printf("How many Element want to remove : ");
scanf("%d", &remove);
for (int i = 0; i < remove; i++)
{
deque();
}
print(f);
}
else{
print(f);
}
}