Linked List implementation

Linked List

Linked List မှာ သုံးမျိုးရှိပါတယ်။ Singly Linked List, Doubly Linked List ရယ် Circular Linked List ဆိုပြီး။ 

Singly Linked List implementation ကို အသေးစိတ်ကျကျရှင်းပြပေးမှာဖြစ်ပြီး၊ ကျန်တဲ့နှစ်ခုကတော့ Singly Linked Link ကိုနားလည်ရင် နားလည်လွယ်ပါတယ်။ OOP အကြောင်းနားလည်ဖို့တော့ လိုအပ်ပါတယ်။ 

အရင်ဆုံး Linked List ကို ဘယ်လို create ရမလဲ ရှင်းပြပါမယ်။ Node ဆိုတဲ့ class ကတော့ linked list ထဲက data တစ်ခုကိုကိုယ်စားပြုပါမယ်။ Linked_List class ကတော့ linked list တစ်ခုလုံးကိုကိုယ်စားပြုပါတယ်။ linked list တစ်ခုမှာ head ဆိုတဲ့ဟာက linked list ရဲ့အပေါ်ဆုံးက data ဖြစ်ပြီး၊ အဲ့တာကိုအသုံးပြုပြီး နောက် node တွေကို ရှာရတာတွေ, ဖျက်တာတွေလုပ်ရပါတယ်။

Singly Linked List မှာ operations 5 ခုရှိပါတယ်။
-insert after node
-insert at front
-insert at end
-delete node
စတာပဲ ဖြစ်ပါတယ်။

insert at front ဆိုတာကတော့ linked list ရဲ့ရှေ့ဆုံးမှာ item တစ်ခုထည့်တာဖြစ်ပြီး။ အောက်က code ကို step by step ရှင်းပြထားပါတယ်။ 
Step by step explaination

insert at end ဆိုတာကတော့ linked list ရဲ့နောက်ဆုံးမှာ data ထည့်တာဖြစ်ပါတယ်။ linked list ရဲ့နောက်ဆုံး node ရဲ့ next က None ဖြစ်ပြီး၊ while loop မှာ while None ဆိုမ run ပါဘူး။ ထို့ကြောင့် while loop ကိုအသုံးပြုပြီး၊ Linked List ရဲ့နောက်ဆုံး node ကိုရှာပြီး အဲ့ node.next မှာ node အသစ်ရဲ့ memory address ကိုထည့်ပေးရုံပါပဲ။
Step by step explaination
insert after node ဆိုတာကတော့ input နှစ်ခုယူမှာဖြစ်ပြီး ပထမက သင်နောက်မှာထည့်ချင်တဲ့ previous node နဲ့ new data ပဲ ဖြစ်ပါတယ်။ previous node ကို Linked List ထဲမှာရှာ၊ previous node ရဲ့ next ကို new data(New Node) ကို point စေပြီး၊ အဲ့ new node ရဲ့ next ကိုတော့ previous node ရဲ့ နောက်က node ကို point စေမှာပါ။
Step by step explaination

delete node ကတော့ Linked List ထဲမှာ delete မယ့် node ကိုရှာပြီး delete လိုက်ရုံပါပဲ။
Step by step explaination

Popular posts from this blog

Data Structure introduction

Algorithm basic examples

Dom introduction