-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinear_queue_double_linked_list.c
More file actions
81 lines (76 loc) · 1.65 KB
/
Linear_queue_double_linked_list.c
File metadata and controls
81 lines (76 loc) · 1.65 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
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *prev;
struct node *next;
};
struct node *f, *r = NULL;
void enqueue(int data){
struct node *newnode = (struct node *)malloc(sizeof(struct node));
newnode -> data = data;
newnode -> next = NULL;
newnode -> prev = NULL;
if (f==NULL){
f = newnode;
r = newnode;
}
else{
r ->next = newnode;
newnode -> prev = r;
r = newnode;
}
}
void dequeue(){
struct node *temp = f;
if (f==NULL){
printf("Queue is empty\n");
return;
}
else if (f == r){
f = NULL;
}
else{
f = f->next;
f->prev -> next = NULL;
f -> prev = NULL;
}
}
void display(){
struct node *current = f;
if (f == NULL){
printf("Queue is Empty\n");
return;
}
else {
printf("Elements of the queue are:\n");
do{
printf("%5d\t", current->data);
printf("%5ld\t",(long)current->prev);
printf("%5ld\t",(long)current->next);
printf("%5ld\t",(long)current);
printf("\n");
current = current->next;
}while(current!=NULL);
}
}
int main(){
int ch=0;
int data;
while (1){
printf("1.Enqueue 2.Dequeue 3.Display 4.Exit\n");
printf("enter choice:");
scanf("%d",&ch);
switch(ch){
case 1: printf("enter:");
scanf("%d",&data);
enqueue(data);
break;
case 2: dequeue();
break;
case 3: display();
break;
case 4: exit(0);
}
}
}