-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue_using_Doubly_Linked_List.c
108 lines (102 loc) · 2.36 KB
/
Queue_using_Doubly_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
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
105
106
107
108
#include<stdio.h>
struct node
{
int info;
struct node *next;
struct node *prev;
};
struct node *front;
struct node *rear;
Insert_Queue_Doubly_Linked_List(int item)
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
if(temp==NULL)
printf("Memory not Initialized..\n\n");
else if(rear==NULL)
{
temp->info=item;
temp->prev=NULL;
temp->next=NULL;
front=temp;
rear=temp;
printf("\t%d is Inserted in Queue using Doubly Linked List..\n\n",temp->info);
}
else
{
temp->info=item;
temp->next=NULL;
temp->prev=rear;
rear->next=temp;
rear=temp;
printf("\t%d is Inserted in Queue using Doubly Linked List..\n\n",temp->info);
}
}
Delete_Queue_Doubly_Linked_List()
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
if(front=NULL)
printf("Queue is UNDERFLOW..\n\n");
else if(front->next==NULL)
{
temp=front;
printf("\t%d is Deleted from Queue ....\n\n",temp->info);
front=NULL;
free(temp);
temp=NULL;
}
else
{
temp=front;
printf("\t%d is Deleted from Queue ....\n\n",temp->info);
front=front->next;
front->prev=NULL;
free(temp);
temp=NULL;
}
}
Display_Queue()
{
struct node *loc;
loc=front;
while(loc!=NULL)
{
printf("\t%d",loc->info);
loc=loc->next;
}
printf("\n");
}
main()
{
int item,choice;
while(1)
{
printf("\t\t***IMPLEMENTATION OF QUEUE USING DOUBLY LINKED LIST***\n\n");
printf("1.Insert in Queue.\n");
printf("2.Delete from Queue.\n");
printf("3.Display all Elements Queue.\n");
printf("\t4.Exit.\n\n");
printf("Enter your Choice :");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter item to be Inserted at Begining :");
scanf("%d",&item);
Insert_Queue_Doubly_Linked_List(item);
break;
case 2:
Delete_Queue_Doubly_Linked_List();
break;
case 3:
printf("\nQueue Elements are as folows : \n");
Display_Queue();
break;
case 4:
exit(0);
default:
printf("Invalid Choice..\n\n");
}
}
}