LinkedList in Java

LinkedList  in Java


A linked list is simply a collection of several nodes with different values. And there is no order for this data structure. Every element in a linked list is called a node. The first node is called the head and the last node is called the tail.

This node can be divided into two parts. They are called Value and Reference.   These nodes are connected to each other with the help of a link, and the reference is used to find the memory address of the next node.    
    
We can't say exactly how a linked list will be stored in memory, it won't be stored in a specific order






There are four main types of linked lists. If they are,

  1. Singly Linked List:
    Each node points to the next node only. Traversal is one-way.

  2. Doubly Linked List:
    Each node has two links — one to the next node and another to the previous node. Allows two-way traversal.

  3. Circular Linked List:
    The last node links back to the first node, forming a loop. It can be singly or doubly circular.

  4. Circular Doubly Linked List:
    A combination of both — nodes are connected in both directions and form a circular loop.


Example code,





Comments

Popular posts from this blog

Java Design Patterns

Application Programming Interface (API)