लिंक्ड सूची के प्रकार

इस ट्यूटोरियल में, आप विभिन्न प्रकार की लिंक्ड सूची सीखेंगे। इसके अलावा, आप सी में लिंक की गई सूची का कार्यान्वयन पाएंगे।

लिंक की गई सूची के प्रकार के बारे में जानने से पहले, सुनिश्चित करें कि आप लिंक्डलिस्ट डेटा संरचना के बारे में जानते हैं।

लिंक्ड लिस्ट के तीन सामान्य प्रकार हैं।

  1. सिंगली लिंक्ड लिस्ट
  2. संदेह से जुड़ी सूची
  3. सर्कुलर लिंक्ड लिस्ट

सिंगली लिंक्ड लिस्ट

यह सबसे आम है। प्रत्येक नोड में अगले नोड में डेटा और एक पॉइंटर होता है।

एकल रूप से जुड़ी सूची

नोड का प्रतिनिधित्व इस प्रकार है:

 struct node ( int data; struct node *next; )

एक तीन सदस्यीय एकल रूप से जुड़ी सूची बनाई जा सकती है:

 /* 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 data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; two->next = three; three->next = NULL; /* Save address of first node in head */ head = one;

संदेह से जुड़ी सूची

हम एक डबल-लिंक की गई सूची में पिछले नोड में एक पॉइंटर जोड़ते हैं। इस प्रकार, हम या तो दिशा में जा सकते हैं: आगे या पीछे।

संदेह से जुड़ी सूची

एक नोड के रूप में प्रतिनिधित्व किया है

 struct node ( int data; struct node *next; struct node *prev; )

एक तीन सदस्यीय लिंक से जुड़ी सूची बनाई जा सकती है

 /* 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 data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; one->prev = NULL; two->next = three; two->prev = one; three->next = NULL; three->prev = two; /* Save address of first node in head */ head = one;

सर्कुलर लिंक्ड लिस्ट

एक सर्कुलर लिंक्ड लिस्ट एक लिंक्ड लिस्ट की भिन्नता है जिसमें अंतिम तत्व पहले तत्व से जुड़ा होता है। यह एक गोलाकार लूप बनाता है।

परिपत्र से जुड़ी सूची

एक सर्कुलर लिंक्ड लिस्ट या तो सिंगलली लिंक्ड या डबल लिंक हो सकती है।

  • पहले लिंक किए गए अंतिम आइटम बिंदुओं की अगली पॉइंटर की एकल लिंक वाली सूची के लिए
  • दोहरी रूप से लिंक की गई सूची में, पहले आइटम बिंदुओं के साथ-साथ अंतिम आइटम के लिए भी संकेत दिया गया है।

एक तीन सदस्यीय परिपत्र से जुड़ी सूची इस प्रकार बनाई जा सकती है:

 /* 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 data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; two->next = three; three->next = one; /* Save address of first node in head */ head = one;

दिलचस्प लेख...