-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreation&displayofdoublylinkedlist.c
63 lines (60 loc) · 1.56 KB
/
creation&displayofdoublylinkedlist.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
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *prevlink;
struct node *nextlink;
};
struct node *head =0;
struct node *newnode , *temp;
int Insert(int num);
int Display();
int main() {
int ch, num;
while(1){
printf("-------Operations of Double Linked List-------\n");
printf("1. Insert\n");
printf("2. Display\n");
printf("3. Exit\n");
printf("Enter Your Choice: \n");
scanf("%d" , &ch);
switch(ch){
case 1: printf("Enter the number you want to Insert: ");
scanf("%d" , &num);
Insert(num);
break;
case 2: Display();
break;
case 3: exit(0);
break;
default: printf("Invalid Choice!\n");
return 0;
}
}
}
int Insert(int num){
struct node *newnode;
newnode = (struct node*)malloc(sizeof(struct node));
newnode -> data = num;
newnode -> nextlink = 0;
newnode -> prevlink = 0;
if(head == 0){
head = temp = newnode;
} else {
temp -> nextlink = newnode;
newnode -> prevlink = temp;
temp = newnode;
}
}
int Display(){
if(head == 0){
printf("List is Empty!");
} else {
struct node *current;
current = head;
while(current != 0){
printf("%d\t" , current -> data);
current = current -> nextlink;
}
} printf("\n");
}