Data Structures and Algorithms - Old Questions

8. What do you mean by double linked list? Explain with example.

5 marks | Asked in 2074

Doubly linked list is a sequence of elements in which every element has links to its previous element and next element in the sequence.

In double linked list, every node has link to its previous node and next node. So, we can traverse forward by using next field and can traverse backward by using previous field. Every node in a double linked list contains three fields and they are shown in the following figure...

Here, 'link1' field is used to store the address of the previous node in the sequence, 'link2' field is used to store the address of the next node in the sequence and 'data' field is used to store the actual value of that node.


Example:


  • In double linked list, the first node must be always pointed by head.
  • Always the previous field of the first node must be NULL.
  • Always the next field of the last node must be NULL

Representation of doubly linked list

struct node

{

int info;

struct node *prev;

struct node *next;

};

typedef struct node NodeType;

NodeType *head=NULL: