what is circular linked list in data structure जाने हिंदी में…

Hello दोस्तों! आज मैं आपको इस पोस्ट में circular linked list in data structure  हिंदी में….   बताऊंगा,

शुरू करने से पहले जान लेते हैं कि इस article में हम क्या-क्या cover करने वाले हैं.

  • Circular Linked List

  • Insert the new node in the circular link list

  • Circular list की traversing

  • Delete an Item from the Circular Link List

  • Application of Link List


Circular Linked List

simple link list मे last node का link part हमेशा NULL होता है लेकिन circular linked list मे list के last node के link part मे हमेशा head का address रहता है अतः circular link list का आखरी node हमेशा list के first node को point करता है ।


Insert the new node in the circular link list

Insert at first

जब circular link list के प्रारम्भ मे किसी नये node को जोड़ना हो तो इसके लिए सबसे पहले यह check करेंगे की list खाली तो नहीं है । यदि head NULL है तो नये node को insert कर दिया जायेगा और head pointer उसे point करेगा । यदि head NULL नहीं है तो head पर पहुँच कर नये node को add कर दिया जायेगा ।

उसके लिए निम्न algorithm है ।

Step1:- new node बनायेंगे।

struct node*new = malloc (sizeof (struct node))

step2:- एक temporary pointer बनाएंगे। जिसमे head का address डालेंगे।

struct node * temp = *head

step3:- new node के information part मे item insert करेंगे।

new -> info = item

step4:- check करेंगे की head NULL है या नहीं यदि head NULL है तो 5th step को execute करेंगे नहीं तो 6th step execute होगा ।

step5:- head मे नया node insert करेंगे ।

head = new node

new node ->next = head

step6:- new node के next part मे head का address डालेंगे ।

new node -> next = head

temp के next part मे जब तक head का address नहीं आ जाता है तब तक temp को आगे बढ़ाएंगे।

while (temp -> next != head)

temp = temp ->next

head मे नये node का address डालेंगे ।

head = new node

temp के next part मे head का address डालेंगे।

temp->next=head

step7:- exit

Function :-

struct node

{

int data;

struct node *next;

};

void append(int x,struct node **p)

{

struct node *temp=*p,*n=malloc(sizeof(struct node));

n->data=x;

printf(“\nappending:%d”,x);

if(temp==NULL)/*list empty*/

{

*p=n;

n->next=n;

return;

}

while(temp->next !=*p)

temp=temp->next;

temp->next=n;

n->next=*p;

}

Insert at Last: –

इसके लिए सबसे पहले यह check करेंगे की list खाली है या नहीं यदि list मे एक भी item नहीं है तो append function को call करेंगे नहीं तो while loop की सहायता से उस node तक पहुंचेगे जंहा temp के next मे head होगा अर्थात last node तक पहुचेंगे अब इस node के info part मे data item insert करेगे और node के next part मे head का address डाल देंगे ।

 इसके  लिए निम्न algorithm है..

Step1:- नये node को memory allocate करेंगे ।

struct node*new = malloc (sizeof (struct node))

step2:- एक temporary pointer बनाएंगे। जिसमे head का address डालेंगे।

struct node * temp = *head

step3:- new node के information part मे item insert करेंगे।

new -> info = item

step4:- check करेंगे की head NULL है या नहीं यदि head NULL है तो 5th step को execute करेंगे नहीं तो 6th step execute होगा ।

step5:- append function को call करेंगे

और return हो जायेंगे

step6:- new node के next part मे head का address डालेंगे ।

new node -> next = head

temp के next part मे जब तक head का address नहीं आ जाता है तब तक temp को आगे बढ़ाएंगे।

while (temp -> next != head)

temp = temp ->next

temp के next part मे head का address डालेंगे।

temp->next=new

step7:- exit


Circular list की traversing:-

Step1:- एक temporary pointer बनाएंगे । जिसमे head का address डालेंगे।

struct node * temp = head

Step 2: – if head = NULL

return

Step 3: – Repeat Step 4 to 5 while temp -> next! = head

Step 4: – print temp -> info

Step 5:- temp = temp -> next

(end of while loop)

Step 6: – print temp -> info

Step 7: – Exit


Delete an Item from the Circular Link List

Delete from first: –

Circular Link List के प्रारम्भ से किसी भी node को delete करने के लिए 3 condition को check करेंगे ।

1. list खाली है ।

2.  list मे केवल एक node है तो उस node को मिटाकर head मे NULL दल देंगे।

3.  list मे एक से ज्यादा node है तो loop की सहायता से first node पर पहुचेंगे और उस node को मिटाकर head को अगले node पर ले जायेंगे। इसके लिए निम्न algorithm है ।

Step1 :- एक temporary pointer लेंगे जिसमे head का address डालेंगे ।

struct node * temp = head

step2 :- यह check करेंगे की head NULL है या नहीं यदि head NULL है तो return हो जायेंगे।

step3 :- यह check करेंगे की head का next head है या नहीं ।

यदि head का next head है तो 4 से 6 तक के step को repeat करेंगे।

step4 :- temp को free कर देंगे ।

step5 :- head मे NULL डालेंगे।

head=NULL

step6:- return

step7:- जब तक temp के next part मे head का address नहीं आ जाता है तब तक temp को आगे बढ़ाएंगे।

while(temp->next != head)

Step 8: – temp=temp->next

Step 9: – head = head -> next (head मे head का next insert करेंगे ।)

Step10:- temp के next मे head डालेंगे ।

temp -> next = head

Step 11: – free(temp)

Step 12: – Exit

Delete from last :-

Circular list के अंत मे से किसी node को हटाने के लिए 3 condition को check करेंगे ।

  1. यदि list खाली है
  2. head मे NULL डाल देंगे. यदि list मे केवल एक node है ।
  3. यदि list मे एक से ज्यादा node है तो loop की सहायता से list के अंतिम node पर पहुचेंगे उस node को मिटाकर उस node के पिछले node मे head का address डालेंगे । इसके लिए निम्न algorithm है ।

Step1 :- एक temporary pointer लेंगे जिसमे head का address डालेंगे ।

struct node * temp = head

step2 :- यह check करेंगे की head NULL है या नहीं head NULL है तो return हो जायेगा

step3 :- यह check करेंगे की head के next मे head है या नहीं यदि head का next head है तो 4 से 6  तक के step को repeat करेंगा ।

step4 :- head मे NULL डालेंगे ।

head=NULL

step5 :- temp को  free कर देंगे ।

free (temp)

Step6 : – return

Step7 :- जब तक temp के next part मे head का address नहीं आ जाता तब तक temp को आगे बढ़ाएँगे  ।

while(temp->next != head)

temp=temp->next

step8 :- temp के next को free कर देंगे ।

free (temp -> next)

step9 :- temp के next मे head डालेंगे ।

temp -> next = head

Step 10 : – Exit


Application of Link List

Linked list एक primitive data structure है जिसे विभिन्न प्रकार की application मे use मे लिया जाता है

उनमे से कुछ application निम्न है

  1. किसी अन्य data structure को implement करने के लिए जैसे stack, queue, tree तथा graph
  2. Name की directory को maintain करने के लिए ।
  3. Login integers पर arithmetic operation perform करने के लिए ।
  4. Polynomials को manipulate करने के लिए ।
  5. Sprats matrix को represent करने के लिए

Note:- ये पोस्ट आपको कैसी लगी आप कमेंट कर के बताईये !अगर आपको कुछ पूछना या अपनी राय देनी  हो तो आप हमे कमेंट या [email protected] ईमेल करके बता सकते है हम पूरी कोसिस करेंगे की आपका रिप्लाई जल्दी से जल्दी दे सखे ….


इसे भी देखे:

Hello दोस्तों! नीचे दिए गए links पर click  करके आपको हम  इस पोस्ट में  (Computer Online Test) की Practice कराएंगे जिससे आप अपने  CCC, O level , कम्प्युटर GK की practice कर सकते है.

इस post के द्वारा आप  अपनी कम्प्युटर की  नॉलेज बड़ सकते है.

उसके साथ ही साथ आप अपने कई प्रकार के पेपरो की भी तैयरी  भी कर सकते है.

जैसे की CCC, O level , कम्प्युटर GK की practice कर सकते है,

 

Leave a Comment