-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublelinkedlist.c
More file actions
79 lines (75 loc) · 1.14 KB
/
doublelinkedlist.c
File metadata and controls
79 lines (75 loc) · 1.14 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
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int info;
struct Node *prev,*next;
}DN;
DN *ptr,*last,*first,*p,*q;
void display(DN*);
void insert(DN*);
DN* create(int);
int main()
{
int n,i,x,y;
first=NULL;
last=NULL;
ptr=NULL;
printf("Enter the no. of elements:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n Enter the element:\n");
scanf("%d",&x);
create(x);
insert(ptr);
display(first);
}
printf("list is created\n");
printf("do u want to enter more elements \n");
printf("if yes enter 1 else 2 \n");
scanf("%d",&y);
while(y==1)
{
printf("\n Enter the element:\n");
scanf("%d",&x);
create(x);
insert(ptr);
display(first);
printf("\n do u want to enter more elements \n");
printf("\n if yes enter 1 else 2 \n");
scanf("%d",&y);
}
return 0;
}
DN* create(int x)
{
ptr=(DN*)malloc(sizeof(DN));
ptr->info=x;
ptr->next=NULL;
ptr->prev=NULL;
}
void insert(DN *ptr)
{
if(first==NULL)
{
last=ptr;
first=ptr;
}
else
{
ptr->next=first;
ptr->prev=NULL;
first->prev=ptr;
first=ptr;
}
}
void display(DN *ptr)
{
ptr=first;
while(ptr!=NULL)
{
printf("%d ",ptr->info);
ptr=ptr->next;
}
}