-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue_Using_Linked_List.c
75 lines (74 loc) · 1.5 KB
/
Queue_Using_Linked_List.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
//C program to implement Queue using linked list.
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int value;
struct Node *link;
};
struct Node *front,*rear,*temp;
void Enqueue();
void Dequeue();
void Display(struct Node *ptr);
int main()
{
system("cls");
int choice;
char c[10];
do
{
printf("\tQUEUE USING LINKED LIST\n");
printf("1.ENQUEUE\n2.DEQUEUE\n3.DISPLAY\n0.EXIT\n");
printf("Enter your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 : Enqueue();
break;
case 2 : Dequeue();
break;
case 3 : Display(front);
break;
case 0 : exit(0);
default: printf("\nInvalid Input");
} printf("Do you want to continue(y/n) : ");
scanf("%s",c);
}while(strcmpi(c,"Y")==0||strcmpi(c,"y")==0);
return 0;
}
void Enqueue()
{
struct Node *ptr;
ptr =(struct Node*)malloc(sizeof(struct Node));
printf("Enter the value :");
scanf("%d",&ptr->value);
ptr->link=NULL;
if(front==NULL)
rear=front=ptr;
else
{
rear->link=ptr;
rear=ptr;
}
}
void Dequeue()
{
if(front==NULL)
printf("Queue Empty\n");
else
{
temp=front;
front=front->link;
free(temp);
}
}
void Display(struct Node *ptr)
{
printf("Value= ");
while(ptr!=NULL)
{
printf("%d\t",ptr->value);
ptr=ptr->link;
}
printf("\n");
}