forked from Sai-02/Data-Structures-using-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubly_Linked_List_Implementation.c
More file actions
53 lines (51 loc) · 1.09 KB
/
Doubly_Linked_List_Implementation.c
File metadata and controls
53 lines (51 loc) · 1.09 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
#include <stdio.h>
#include <stdlib.h>
struct node
{
int info;
struct node *next;
struct node *prev;
};
int main()
{
int n;
scanf("%d", &n);
struct node *head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
head->prev = NULL;
struct node *current = head;
// struct node* previous=NULL;
for (int i = 0; i < n; i++)
{
int value;
scanf("%d", &value);
if (i == 0)
{
current->info = value;
current->prev = NULL;
}
else
{
struct node *new = (struct node *)malloc(sizeof(struct node));
new->info = value;
new->prev = current;
new->next = NULL;
current->next = new;
current = current->next;
}
}
struct node *temp = head;
// printf("\n");
while (temp->next != NULL)
{
printf("%d ", temp->info);
temp = temp->next;
}
printf("%d\n", temp->info);
while (temp != NULL)
{
printf("%d ", temp->info);
temp = temp->prev;
}
return 0;
}