DATA STRUCTURES

what is linked list data structure

What is a Linked list?

Linked list is linear data structure which stores its data elements called nodes in random memory locations with the help of pointers. A node consists of two parts one data part and second link part. Inside data part there can be any type of data like integer, char, float, or a structure and inside link part there can only be pointer type data that refers to next node in the list. 

Using pointers list is created like a chain of nodes first node is linked to a pointer variable sometimes called as head or start which represents the beginning of the list, the last or end node contains NULL in the link part which represents end of list.

Accessing these elements is always sequential means if we want to access a particular element we have to traverse the hole list until we find the match for our data element to be accessed. Unlike arrays there is no random access of elements in the linked list because in arrays there is a subscript while as in linked list we do not have such facility. Hence Linked list is a sequential access list. 

Types of linked lists 

1. Singly linked.

2. Circular linked list.

3. Doubly linked list.

4. Doubly circular linked list.

 

Singly Linked List:

Singly linked list is a list where  traversing of list is unidirectional means we can traverse the linked list in one direction. In singly linked list there is no reverse traversing.

syntax/structure

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

 

Circular Linked list:

A circular linked list is a collection of elements in which every element has a link to its next element in the sequence and the last element has a link to the first element. That means circular linked list is similar to the singly linked list except that the last node points to the first node in the list. Hence we can traverse in a circular fashion.

Here the beginning of the list is pointed by start or head pointer and the last node does not contain NULL in next pointer instead it contains the address of the first node in the list.

syntax 

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

 

Doubly Linked List:

Doubly linked list is a list in which a node has three parts data part and two pointers in which first pointer(previous) contains the address of the previous node and second pointer(next) contains the address of next node in the list. In Doubly linked list we can traverse in both directions means there is also a reverse direction in the list. Here also starting of linked list is pointed out by start pointer and end of list is marked by NULL in the next pointer of the last node.

syntax/structure

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

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button