-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoublyLinkedList.c
50 lines (43 loc) · 1021 Bytes
/
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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *lptr;
struct node *rptr;
};
// Traversing is as same as
void traverseDoubly(struct node* head)
{
struct node *p = head;
while(p!=NULL)
{
printf("\nYour element is: %d",p->data);
p = p->rptr;
}
}
int main()
{
struct node *first;
struct node *second;
struct node *third;
struct node *fourth;
first = (struct node*)malloc(sizeof(struct node));
second = (struct node*)malloc(sizeof(struct node));
third = (struct node*)malloc(sizeof(struct node));
fourth = (struct node*)malloc(sizeof(struct node));
first->lptr=NULL;
first->data=10;
first->rptr=second;
second->data=20;
second->lptr=first;
second->rptr=third;
third->lptr=second;
third->data=30;
third->rptr=fourth;
fourth->lptr=third;
fourth->data=40;
fourth->rptr=NULL;
traverseDoubly(first);
}