### Doubly linked and circular lists

• More complex list structures

• Sometimes, people use doubly linked list to simplify some list manipulation operations.

• Doubly linked list = a linked data structure that consists of a set of sequentially linked records called nodes where:

 Each node contains two links one of the links references the previousnode and the other link references to next node in the sequence of nodes

• There are 2 popular types of doubly linked lists:

• Example of an open doubly linked list:

Explanation:

• A Node has 2 links:

 ``` public class Node { public double value; public Node prev; // Points to the previous node public Node next; // Points to the next node ... } ```

• The purpose of the next link is to allow the user to access the next node (it has the same purpose as what we have learned)

• The purpose of the prev link is to allow the user to access the previous node

 This makes linking and unlinking easier to program because we can access the one-before-the deletion node from the deletion node using the prev link.

• The last node of the forward chain (formed by the next variables has:

 ``` next == null ```

• The last node of the reverse chain (formed by the prev variables has:

 ``` prev == null ```

• Example of an open doubly linked list:

Explanation:

• A Node has 2 links:

 ``` public class Node { public double value; public Node prev; // Points to the previous node public Node next; // Points to the next node ... } ```

• The purpose of the next link is to allow the user to access the next node (it has the same purpose as what we have learned)

• The purpose of the prev link is to allow the user to access the previous node

 This makes linking and unlinking easier to program because we can access the one-before-the deletion node from the deletion node using the prev link.

• The last node of the forward chain (formed by the next variables has:

 ``` next == first node ```

• The last node of the reverse chain (formed by the prev variables has:

 ``` prev == last node ```

• Note: the circular doubly linked list is very flexible:

• You can insert at the tail of the list using:

to find the last node in the list

• List maintenance

• Insert and delete operations on doubly linked list must:

 Update the next link variable to point to the correct successor node,     but also Update the prev link variable to point to the correct predecessor node !!!

• If you understand how to maintain the links from the list discussions, you should have no problem figuring out what to do to maintain a doubly linked list

(At least, you should be able to follow the algorithms in books or wikipedia and understand them).