Open In App

Applications, Advantages and Disadvantages of Linked List

The various types of linked lists are as follows:

          Example: 






class Node {
public:
    int data;
    Node* next;
 
    Node(int data) {
        this->data = data;
        this->next = nullptr;
    }
};
 
class SinglyLinkedList {
public:
    Node* head;
 
    SinglyLinkedList() {
        this->head = nullptr;
    }
 
    void add_node(int data) {
        Node* new_node = new Node(data);
        new_node->next = this->head;
        this->head = new_node;
    }
};




class Node:
  def __init__(self, data):
    self.data = data
    self.next = None
 
class SinglyLinkedList:
  def __init__(self):
    self.head = None
     
  def add_node(self, data):
    new_node = Node(data)
    new_node.next = self.head
    self.head = new_node




class Node {
    int data;
    Node next;
 
    Node(int d) {
        data = d;
        next = null;
    }
}
 
class SinglyLinkedList {
    Node head;
 
    SinglyLinkedList() {
        head = null;
    }
 
    void add_node(int data) {
        Node new_node = new Node(data);
        new_node.next = head;
        head = new_node;
    }
}




using System;
 
public class Node {
    public int data;
    public Node next;
 
    public Node(int d) {
        data = d;
        next = null;
    }
}
 
public class SinglyLinkedList {
    public Node head;
 
    public SinglyLinkedList() {
        head = null;
    }
 
    public void add_node(int data) {
        Node new_node = new Node(data);
        new_node.next = head;
        head = new_node;
    }
}




class Node {
  constructor(data) {
    this.data = data;
    this.next = null;
  }
}
 
class SinglyLinkedList {
  constructor() {
    this.head = null;
  }
 
  add_node(data) {
    let new_node = new Node(data);
    new_node.next = this.head;
    this.head = new_node;
  }
}

          Example:




#include <stdio.h>
#include <stdlib.h>
 
struct Node {
    int data;
    struct Node* next;
    struct Node* prev;
};
 
struct DoublyLinkedList {
    struct Node* head;
};
 
void addNode(struct DoublyLinkedList* list, int data) {
    struct Node* newNode = (struct Node*) malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = list->head;
    newNode->prev = NULL;
    if (list->head != NULL) {
        list->head->prev = newNode;
    }
    list->head = newNode;
}




class Node {
public:
int data;
Node* next;
Node* prev;
Node(int d) : data(d), next(nullptr), prev(nullptr) {}
};
 
class DoublyLinkedList {
public:
Node* head;
DoublyLinkedList() : head(nullptr) {}
 
void add_node(int data) {
    Node* new_node = new Node(data);
    new_node->next = head;
    if (head != nullptr) {
        head->prev = new_node;
    }
    head = new_node;
}
};




class Node:
  def __init__(self, data):
    self.data = data
    self.next = None
    self.prev = None
 
class DoublyLinkedList:
  def __init__(self):
    self.head = None
     
  def add_node(self, data):
    new_node = Node(data)
    new_node.next = self.head
    if self.head is not None:
      self.head.prev = new_node
    self.head = new_node




public class Node {
    public int data;
    public Node next;
    public Node prev;
     
    public Node(int d) {
        data = d;
        next = null;
        prev = null;
    }
}
 
public class DoublyLinkedList {
    public Node head;
     
    public DoublyLinkedList() {
        head = null;
    }
     
    public void addNode(int data) {
        Node newNode = new Node(data);
        newNode.next = head;
        if (head != null) {
            head.prev = newNode;
        }
        head = newNode;
    }
}




public class Node {
    public int data;
    public Node next;
    public Node prev;
     
    public Node(int d) {
        data = d;
        next = null;
        prev = null;
    }
}
 
public class DoublyLinkedList {
    public Node head;
     
    public DoublyLinkedList() {
        head = null;
    }
     
    public void AddNode(int data) {
        Node newNode = new Node(data);
        newNode.next = head;
        if (head != null) {
            head.prev = newNode;
        }
        head = newNode;
    }
}




class Node {
  constructor(d) {
    this.data = d;
    this.next = null;
    this.prev = null;
  }
}
 
class DoublyLinkedList {
  constructor() {
    this.head = null;
  }
   
  addNode(data) {
    const newNode = new Node(data);
    newNode.next = this.head;
    if (this.head !== null) {
      this.head.prev = newNode;
    }
    this.head = newNode;
  }
}

          Example:






struct Node {
    int data;
    struct Node* next;
};
 
struct CircularLinkedList {
    struct Node* head;
};
 
void add_node(struct CircularLinkedList* list, int data) {
    struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
    new_node->data = data;
    new_node->next = NULL;
 
    if (list->head == NULL) {
        list->head = new_node;
        new_node->next = new_node;
        return;
    }
 
    struct Node* current = list->head;
 
    while (current->next != list->head) {
        current = current->next;
    }
 
    current->next = new_node;
    new_node->next = list->head;
}




class Node {
public:
int data;
Node* next;
Node(int d) : data(d), next(nullptr) {}
};
 
class CircularLinkedList {
public:
Node* head;
CircularLinkedList() : head(nullptr) {}
 
void add_node(int data) {
    Node* new_node = new Node(data);
    if (head == nullptr) {
        head = new_node;
        new_node->next = head;
        return;
    }
    Node* current = head;
    while (current->next != head) {
        current = current->next;
    }
    current->next = new_node;
    new_node->next = head;
}
};




class Node {
    public int data;
    public Node next;
 
    public Node(int d) {
        data = d;
        next = null;
    }
}
 
class CircularLinkedList {
    public Node head;
 
    public CircularLinkedList() {
        head = null;
    }
 
    public void add_node(int data) {
        Node new_node = new Node(data);
        if (head == null) {
            head = new_node;
            new_node.next = head;
            return;
        }
        Node current = head;
        while (current.next != head) {
            current = current.next;
        }
        current.next = new_node;
        new_node.next = head;
    }
}




class Node:
  def __init__(self, data):
    self.data = data
    self.next = None
 
class CircularLinkedList:
  def __init__(self):
    self.head = None
     
  def add_node(self, data):
    new_node = Node(data)
    if self.head is None:
      self.head = new_node
      new_node.next = self.head
      return
    current = self.head
    while current.next != self.head:
      current = current.next
    current.next = new_node
    new_node.next = self.head




class Node {
  constructor(data) {
    this.data = data;
    this.next = null;
  }
}
 
class CircularLinkedList {
  constructor() {
    this.head = null;
  }
 
  add_node(data) {
    const new_node = new Node(data);
    if (this.head === null) {
      this.head = new_node;
      new_node.next = this.head;
      return;
    }
    let current = this.head;
    while (current.next !== this.head) {
      current = current.next;
    }
    current.next = new_node;
    new_node.next = this.head;
  }
}




public class Node
{
    public int data;
    public Node next;
 
    public Node(int d)
    {
        data = d;
        next = null;
    }
}
 
public class CircularLinkedList
{
    public Node head;
 
    public CircularLinkedList()
    {
        head = null;
    }
 
    public void add_node(int data)
    {
        Node new_node = new Node(data);
 
        if (head == null)
        {
            head = new_node;
            new_node.next = head;
            return;
        }
 
        Node current = head;
 
        while (current.next != head)
        {
            current = current.next;
        }
 
        current.next = new_node;
        new_node.next = head;
    }
}

Linked Lists are most commonly used for:

Applications of Linked Lists:

Applications of Linked Lists in real world: 

Advantages of Linked Lists:

Linked lists are a popular data structure in computer science, and have a number of advantages over other data structures, such as arrays. Some of the key advantages of linked lists are:

In conclusion, linked lists are a powerful and flexible data structure that have a number of advantages over other data structures, making them a great choice for solving many data structure and algorithm problems.

Disadvantages of Linked Lists:

Linked lists are a popular data structure in computer science, but like any other data structure, they have certain disadvantages as well. Some of the key disadvantages of linked lists are:

In conclusion, linked lists are a powerful and flexible data structure, but they have certain disadvantages that need to be taken into consideration when deciding whether to use them or not. For example, if you need fast access time, arrays might be a better choice, but if you need to insert or delete elements frequently, linked lists might be the better choice.


Article Tags :