-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoublyLinkedList.c
98 lines (96 loc) · 1.4 KB
/
doublyLinkedList.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
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* prev;
struct node* next;
};
struct node* start=NULL;
void insertLast(int data)
{
struct node *temp;
temp=(struct node*)malloc(sizeof(struct node*));
temp->data=data;
temp->next=NULL;
if(start==NULL)
{
start=temp;
temp->prev=NULL;
}
else
{
struct node *head;
head=start;
while(head->next!=NULL)
head=head->next;
temp->prev=head->next;
head->next=temp;
}
}
void deleteLast()
{
if(start==NULL)
printf("Nothing to delete\n");
struct node *temp;
temp=start;
while(temp->next!=NULL)
temp=temp->next;
if(start->next==NULL)
start=NULL;
else
{
temp->prev->next=NULL;
free(temp);
}
}
void display()
{
if(start==NULL)
printf("Nothing to display\n");
else
{
while(start!=NULL)
{
printf("the data is :%d\n",start->data);
start=(start->next);
}
}
}
int choose()
{
int ch;
printf("Enter ur choice\n");
printf("1) Insert Last\n");
printf("2)Delete Last\n");
printf("3)Display\n");
printf("4)Exit\n");
scanf("%d",&ch);
return(ch);
}
void main()
{
while(1)
{
switch(choose())
{
int val;
case 1:
printf("Enter the value u want to Enter\n");
scanf("%d",&val);
insertLast(val);
break;
case 2:
deleteLast();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("Invalid Option");
}
}
}