Skip to content

LinkList

Vishnu Garg edited this page Aug 2, 2018 · 2 revisions

Link List implementation and internal working algorithm

A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers as shown in the below image:

LinkedList Implementation

package java.util;
public class LinkedList implements List,Deque {
  private Node first;
  private Node last;
  public E get(int index) {…}
  public boolean add(E e) {…}
  public E remove(int index) {…}
  […]
  }

Node Implementation

public class Node {
    private E item;
    private Node previous;
    private Node next;
   public Node(E element, Node previous, Node next) {
       this.item = element;
       this.next = next;
       this.previous = previous;
   }  
[...]
}

Refrencses

Every single element in a Doubly Linked List has a reference to its previous and next elements as well as a reference to an item, simplified as a number within a yellow box on this image above.

Clone this wiki locally