Advanced Java Tutorial


Total available pages count: 55
Subject - Java Technologies

Linkedlist

LinkedList
LinkedList is a linear data structure, where elements are not stored at a contiguous memory location.
The elements are linked to each other by providing one additional data along with the element, that is the address of the next element. The variable that stores the address of the next element is called a pointer. We can say the linked list contains two-part

  • data element
  • pointer

LinkedList also defined as a collection of nodes in which one node connected to another & the node consists of two-part that is  1st is the data part  & 2nd is the address part.

Type of LinkedList

  • Singly LinkedList
  • Doubly LinkedList
  • Circular LinkedList

Singly LinkedList

Singly LinkedList stores data and give reference to the next node or null value.it is also known as a one-way list as they contain a node with a single pointer that pointing to the next node.

Represent node in singly LinkedList

struct node
{
	int data;
	struct node *next;
}

 

Doubly LinkedList

Doubly LinkedList contains two pointers, one pointing to the next node & one pointing to the previous node in linear. It allows doing traverse in both directions of the list.

Represent node in doubly LinkedList:

struct node
{
	int data;
	struct node *next;
	struct node *prev;
}

 

Circular LinkedList

A circular LinkedList list is a list where all the nodes arranged in form of a circular way. There is no NULL node at the end. We can point to any node as the first node.

Representation of circular LinkedList

struct node
{
	int data;
	struct node *next;
}

 

  • It is a linear data structure
  • As per memory availability, it stores the elements
  • Dynamic in size
  • We can access an element in a linear way
  • Stores similar element
  • Easy to insert & delete
  • The starting node is key which is typically termed as head
  • No wastage in memory

Limitation

  • If a head node gets lost, LinkedList is lost
  • Random access not possible


Comments