Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » Data Structure » Linked List in Data Structure and Algorithm, Types, Operations

  • Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth
    Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth Biography
  • States of Matter : Physical Properties of Matter (Solid, Liquid, Gas)
    States of Matter | Physical Properties of Matter (Solid, Liquid, Gas) Science
  • Mahatma Gandhi Essay in Hindi | Gandhiji Biography
    Mahatma Gandhi Essay in Hindi | Gandhiji Biography Biography
  • What is Adjective in Hindi (विशेषण क्या है?)
    What is Adjective in Hindi (विशेषण क्या है?) Grammar
  • Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi
    Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi Biography
  • Hima Das Biography | भारतीय धाविका हिमा दास का जीवन परिचय
    Hima Das Biography | भारतीय धाविका हिमा दास का जीवन परिचय Biography
  • Balkand Ramayana story in Hindi | रामायण बाल कांड राम का जन्म
    Balkand Ramayana story in Hindi | रामायण बाल कांड राम का जन्म Spiritual
  • Bhagat Singh Biography in Hindi (भगत सिंह का जीवन परिचय)
    Bhagat Singh Biography in Hindi (भगत सिंह का जीवन परिचय) Biography

Linked List in Data Structure and Algorithm, Types, Operations

Posted on April 16, 2022April 16, 2022 By GeekCer Education No Comments on Linked List in Data Structure and Algorithm, Types, Operations
Linked List in Data Structure and Algorithm, Types, Operations

A linked list is a data structure that simulates a dynamic list of data items without knowing the size at compile time. During the runtime, the linked list may grow or shrink.

We are all familiar with the idea of an array, which is represented in memory using sequential mapping. It has a fixed size. The fundamental drawback of the array idea is that inserting or removing components from a specific point in the array is a time-consuming process.

Table of Contents

  • Key points of Linked List in Data Structure
  • Linked List Representation in Data Structure
  • Linked List Program in C
  • Types of Linked List in Data Structure
  • Basic Operations of Linked List in Data Structure

Key points of Linked List in Data Structure

  • We should use Linked List when the number of data elements is unknown before execution.
  • The data from the linked list is accessed using an start pointer.
  • Linked list stores data in the form of nodes. And linked list allocates memory at runtime to create nodes.
  • Because memory allocation and deallocation are done at runtime, the speed is lower.

Linked List Representation in Data Structure

If we use a particular size array to represent the data item, yet we may unable to fill the entire array during runtime. There will be wastage or storage in this instance.

Inserting components at certain locations may need a lot of array shifting.

Linked lists can solve many of the difficulties that arrays have. The element can be placed at any point in the linked list. However, in order to create such an element, we must link the element to the one before it.

The three elements that make up a linked list are as follows:

  1. item– An element is a type of data that may be stored in each link in a linked list.
  2. link–  next that points to the next link.

We use a struct to wrap both the data item and the next node reference:

 struct node {
       int item;
       struct node * link;
 };

Linked List Program in C

The program below is for adding a node to an existing list. For this reason, we designed the insertItem function.

The number of nodes in the list is read by the main function. The list elements are shown using the displayList function.


#include <stdio.h>
#include <stdlib.h>
struct node {
   int item;
   struct node * link;
};
void displayList(struct node * start) {
  struct node * temp;
  temp = start;
  printf("The item values in the list are\n");
  if (start != NULL) {
    do {
      printf("%d\t", temp -> item);
      temp = temp -> link;
    } while (temp != start);
  } else
    printf("The list is empty\n");
}
struct node* insertItem(struct node * start, int data) {
  struct node * temp;
  if (start == NULL) {
    start = (struct node * ) malloc(sizeof(struct node));
    if (start == NULL) {
      printf("Error\n");
      exit(0);
    }
    start -> item = data;
    start -> link = start;
  } else {
    temp = start;
    while (temp -> link != start)
      temp = temp -> link;
    temp -> link = (struct node * ) malloc(sizeof(struct node));
    if (temp -> link == NULL) {
      printf("Error\n");
      exit(0);
    }
    temp = temp -> link;
    temp -> item = data;
    temp -> link = start;
  }
  return (start);
}
int main() {
  int numberOfNodes;
  int data;
  struct node * start = NULL;
  printf("Enter the number of nodes to be created \n");
  scanf("%d", & numberOfNodes);
  while (numberOfNodes > 0) {
    printf("Enter the item value for node\n");
    scanf("%d", & data);
    start = insertItem(start, data);
    numberOfNodes--;
  }
  printf("The list is\n");
  displayList(start);
  return 0;
}


Output:
Enter the number of nodes to be created 
3
Enter the item value for node
10
Enter the item value for node
20
Enter the item value for node
30
The list is
The item values in the list are
10      20      30

Types of Linked List in Data Structure

The many forms of linked lists are shown below.

  • Simple Linked List
  • Doubly Linked List
  • Circular Linked List

Basic Operations of Linked List in Data Structure

The fundamental operations enabled by a list are as follows.

  • Insertion : For adding an data at the beginning.
  • Deletion : For removing an data at the beginning.
  • Show : Shows the list items.
  • Search : Search specified key element from list.
  • Delete : Delete the specified key element.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

C Language, Data Structure

Post navigation

Previous Post: Linear search algorithm | Linear search program in C, Example
Next Post: Dynamic memory allocation in C using malloc, realloc, calloc and free

More Related Articles

File Handling in C with examples | File Operations in C File Handling in C with examples | File Operations in C C Language
Pointers in C Programming, Definition, Types & Example Pointers in C Programming, Definition, Types & Example C Language
Array in C programming | Character Array in C Array in C programming | Character Array in C C Language
Statements in C Language | Types of statements in C Language Statements in C Language | Types of statements in C Language C Language
Programming with C Language Tutorial Programming with C Language Tutorial C Language
Constants and Operators in C Language Constants and Operators in C Language C Language

Leave a Reply Cancel reply

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

  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved