Doubly Linked Lists

What are doubly linked lists?

Doubly Linked Lists are similar to singular linked lists except they contain access to the preview node in the list. Each node contains a pointer to the next node and a pointer to the previous node in addition to the data field. The head points to the first node to access the list. This makes relocating memory more efficient.

Implementation of doubly linked list

The implementation of the list node class in the linked list would look like the code segment below, which includes the prev pointer that will be used to iterate & traverse the list.

private static class ListNode﹤E﹥ {
	private E info; 
	private ListNode﹤E﹥ next;
	private ListNode﹤E﹥ prev;

	public ListNode(){
		next ﹦ null;
		info ﹦ null;
		prev ﹦ null;
	}

  public ListNode(E obj, ListNode ﹤E﹥ nextNode, ListNode﹤E﹥ prevNode){
      info ﹦ obj;
      next ﹦ nextNode;
      prev ﹦ prevNode;
    }
  }
}
Full course
Next Lesson