Site icon

Linked List इन data structure क्या है ? हिन्दी में

Linked List kya hai?

Linked List एक Linear data structure है , जिसके elements आस पास (stored) जमा नहीं है । एक Linked list के अंदर elements pointers कि मदद से जुड़े होते है ।

आसान शब्दों मे , एक linked list के अंदर nodes होते है , जहा हर node में एक data कोश और अगले node के लिए reference (Link) stored होती है ।

अब हमे कही से तो शुरुआत करनी होगी , इसलिए सबसे पहले node को HEAD कहा गया ।

ऐसे ही आखरी node को NULL कहा गया जोकि खाली होता है। ऐसे मे किसी प्रोग्राम को linked list के अंतिम node के बारे मे पता चलता है।

इसके प्रतिरूप

आइए देखते है कि हर node को किस तरह दर्शाया जाता है –

अब चलिए देखते है कि ये प्रोग्राम पे कैसा दिखता है :-

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

हर एक struct node के पास एक data item और दूसरे struct node का pointer होता है। आइए एक सरल linked list बनाते है जिसमे 3 items है:-

/* Nodes का initialization*/
struct node *head;
struct node *one = NULL;
struct node *two = NULL;
struct node *three = NULL;

/* Memory Allocation */
one = malloc(sizeof(struct node));
two = malloc(sizeof(struct node));
three = malloc(sizeof(struct node));

/* Data values को aasign करना */
one->data = 1;
two->data = 2;
three->data=3;

/* Connect nodes */
one->next = two;
two->next = three;
three->next = NULL;

/* पहले node का address head मे save करना */
head = one;

ऊपर लिखे कोड मे कोई line न clear हो तो pointers और structs के बारे मे पढ़ें ।

linked list in data structure

एक linked लिस्ट कि chain को तोड़ सकने और वापस जुडने कि क्षमता ही इसे खास बनती है।

जैसे अगर आपको एक element 4 को 1 और 2 के बीच लगाना है तो उसके लिए steps निम्नलिखित है :-

  • एक नया struct node बनाना होगा और उसको memory allocate करना होगा
  • उसमे data value 4 डालें
  • इस node के pointer को “2” वाले struct node कि तरफ point करवाना होगा
  • “1” के अगले pointer को “4” वाले node कि तरफ change करना होगा।

किसी array मे ऐसा कुछ करने के लिए आस पास के सभी elements को shift करना पड़ता ।

linked list in c हिन्दी

// Linked list के C में implementation

#include <stdio.h>
#include <stdlib.h>

// Creating node
struct node {
  int value;
  struct node *next;
};

// print the linked list values 
void printLinkedlist(struct node *p) {
  while (p != NULL) 
{
    printf("%d ", p->value);
    p = p->next;
  }
}

int main() {
  // Initialize nodes
  struct node *head;
  struct node *one = NULL;
  struct node *two = NULL;
  struct node *three = NULL;

  // Allocate memory
  one = malloc(sizeof(struct node));
  two = malloc(sizeof(struct node));
  three = malloc(sizeof(struct node));

  // Assign value values
  one->value = 1;
  two->value = 2;
  three->value = 3;

  // Connect nodes
  one->next = two;
  two->next = three;
  three->next = NULL;

  // printing node-value
  head = one;
  printLinkedlist(head);
}

linked list in java

// Linked list का implementation Java में 

class LinkedList {
  // Creating a node
  Node head;

  static class Node {
    int value;
    Node next;

    Node(int d) {
      value = d;
      next = null;
    }
  }

  pub static void main(String[] args) {
    LinkedList linkedList = new LinkedList();

    // Assign value values
    linkedList.head = new Node(1);
    Node second = new Node(2);
    Node third = new Node(3);

    // Connect nodess
    linkedList.head.next = second;
    second.next = third;

    // printing node-value
    while (linkedList.head != null) {
      System.out.print(linkedList.head.value + " ");
      linkedList.head = linkedList.head.next;
    }
  }
}

in python click here

LINKED LIST कि उपयोगिता

Lists सबसे मशहूर और कुशल data structure है , जिसका implementation लगभग हर programming language – जैसे C, C++, PYTHON, JAVA and C#.

इसके अलावा pointers मे महारत हासिल करने के लिए भी linked list काम आता है। Graph और trees के लिए भी इसे पढ़ना जरूरी है।

निम्न वो विषय है जिनमे linked का उपयोग होगा ।

  • Dynamic memory allocation
  • Implementation in stack and queue
  • In undoing functionality of Softwares
  • In Hash Tables, Graphs

Linked list कि Time complexity

Worst CaseAverage Case
SearchO(n)O(n)
Insert/DeletionO(1)O(1)
Space Complexity : O(n)
Exit mobile version