-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueUsingLinkedList.c
More file actions
92 lines (90 loc) · 1.74 KB
/
Copy pathQueueUsingLinkedList.c
File metadata and controls
92 lines (90 loc) · 1.74 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
#include<stdio.h>
#include<stdlib.h>
#include <stdbool.h>
#include <stddef.h>
struct Node
{
int info;
struct Node *next;
};
typedef struct Node node;
node *prev,*curr,*F,*R= NULL;
node *p;
node *newnode(int val)
{
p = (node *)malloc(sizeof(node));
p->info = val;
p->next = NULL;
return p;
}
void enqueue_LL(int ele)
{
p=newnode(ele);
if(F==NULL)
F=R=p;
else
R->next=p;
R=p;
}
int dequeue_LL()
{
int ele = F->info;
curr=F;
if(F==R)
{
F=R=NULL;
return ele;
}
else
{
F=F->next;
}
free(curr);
return (ele);
}
void Display()
{
curr=F;
if(F == NULL){
printf("Queue is Empty\n");
}
while (curr->next!=NULL)
{
printf("%d\t",curr->info);
curr=curr->next;
}
printf("%d\n",curr->info);
}
int main()
{
int ch,ele;
printf("QUEUE USING LINKED LIST");
do
{
printf("\n\nChoose:\n1.Enqueue_LL\n2.Dequeue_LL\n3.Display\n4.Exit\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter the number to be Inserted : ");
scanf("%d",&ele);
enqueue_LL(ele);
break;
case 2: if(F == NULL)
printf("Queue is Empty\n");
else
{
ele = dequeue_LL();
printf("\nDequeued: %d",ele);
}
break;
case 3: printf("\nThe Elements in the Queue :\n");
Display();
break;
case 4: break;
default : printf("\nINVALID CHOICE");
}
}
while(ch!=4);
return 0;
}