forked from somiljain7/data-structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoubly_linklist.c
More file actions
68 lines (63 loc) · 1.16 KB
/
doubly_linklist.c
File metadata and controls
68 lines (63 loc) · 1.16 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
#include<stdio.h>
#include<stdlib.h>
struct Node{
int data;
struct Node *next;
struct Node *prev;
}Node;
struct Node *head;
void insert_beg(int x)
{
struct Node *temp = (struct Node*)malloc(sizeof(struct Node));
temp->data = x;
temp->next = NULL;
temp->prev = NULL;
if(head!=NULL)
{
temp->next = head;
head->prev = temp;
}
head = temp;
}
void print()
{
struct Node *temp = head;
printf("\n LIST IS \n");
while(temp!=NULL)
{
printf("%d", temp->data);
temp = temp->next;
}
printf("\n");
}
void reverse(){
struct Node *temp = head;
if(temp==NULL)
return;
while(temp->next!=NULL)
{
temp=temp->next;
}
printf("\n REVERSE LIST IS");
while(temp!=NULL)
{
printf("%d", temp->data);
temp = temp->prev;
}
printf("\n");
}
int main()
{
int n,x;
head = NULL;
printf("enter the total number of elements");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf(" \n enter the data \n");
scanf("%d",&x);
insert_beg(x);
}
reverse();
return 0;
}