Doubly Linked List
In this list each and every node is connected with one another in both direction so , the traversal can be done from head node to tail node and vice-versa.
Here each node has been divided into three parts:-
1)Information part
2)Left Pointer
3)Right Pointer
1)Information Part-It holds any type of value which may be numeric or character.
2)Left Pointer/Previous Part-It holds the address of predecessor node/previous node.
3)Right Pointer/Next Part-It hold the address of successor node/Next node.
Pointer start point first/head node
Previous part of first node and next part of last node will be always null
Next part of each node contains address of successor node
Previous part of each node contain address of predecessor node
If a node contains null in the previous part it mean it is first node of the list
If a node contains null in the next part it mean it is last node of the list
Basic operation of Doubly Linked List
Creation
Traversal
Insertion
Deletion
Node of Doubly Linked List
struct node
{
int info;
struct node *prev;
struct node *nezt;
}
Insertion:-
Insertion in an empty list
Insertion at the beginning
Insertion at the end
Insertion at nth place
Insertion in an empty list-
struct node
{
int info;
struct node *prev;
struct node *next;
}
struct node *tmp;
tmp=(struct node*)malloc (sizeof(struct node))
tmp--->info=2
tmp--->prev=null
tmp--->next=null
start=tmp
Insertion at the beginning
struct node
{
int info;
struct node *prev;
struct node *next;
}
struct node *tmp;
tmp=(strruct node *)malloc(sizeof(struct node))
tmp--->info=2
tmp--->prev=null
tmp--->next=start
tmp--->prev=tmp
start=tmp
Here each node has been divided into three parts:-
1)Information part
2)Left Pointer
3)Right Pointer
1)Information Part-It holds any type of value which may be numeric or character.
2)Left Pointer/Previous Part-It holds the address of predecessor node/previous node.
3)Right Pointer/Next Part-It hold the address of successor node/Next node.
Pointer start point first/head node
Previous part of first node and next part of last node will be always null
Next part of each node contains address of successor node
Previous part of each node contain address of predecessor node
If a node contains null in the previous part it mean it is first node of the list
If a node contains null in the next part it mean it is last node of the list
Basic operation of Doubly Linked List
Creation
Traversal
Insertion
Deletion
Node of Doubly Linked List
struct node
{
int info;
struct node *prev;
struct node *nezt;
}
Insertion:-
Insertion in an empty list
Insertion at the beginning
Insertion at the end
Insertion at nth place
Insertion in an empty list-
struct node
{
int info;
struct node *prev;
struct node *next;
}
struct node *tmp;
tmp=(struct node*)malloc (sizeof(struct node))
tmp--->info=2
tmp--->prev=null
tmp--->next=null
start=tmp
Insertion at the beginning
struct node
{
int info;
struct node *prev;
struct node *next;
}
struct node *tmp;
tmp=(strruct node *)malloc(sizeof(struct node))
tmp--->info=2
tmp--->prev=null
tmp--->next=start
tmp--->prev=tmp
start=tmp
No comments