昨天講了單向跟雙向鏈結,今天來講最後一個!!環狀鏈結ლ(́◕◞౪◟◕‵ლ)
還有講一些Linked List 基本操作的pseudo code
Lengths(S:Singly Linked List){
P=S;
count=0;
while(P!=Null)do{
count++;
P=P➝link;
}
return count;
}
Time=O(n)
Lengths(C:Circular Linked List){
if(C==Null)then return 0;
else{
P=C;
count=0;
repeat{
count++;
P=P➝link;
}until(P==C)
return count;
}
}
Time=O(n)
Concatenate(A,B,C:Circular Linked List){
C=Null;
if(A!=Null and B==Null) then C==A;
else if(A==Null and B!=Null) then C==B;
else if(A!=Null and B!=Null) then{
① P = A➝link;
②A➝link = B➝link;
③B➝link = P;
④C=P;
}
return C;
}
Time=O(1)
(圖)
將link的方向改變(ノ◕ヮ◕)ノ*:・゚✧
Invert(s:Singly Linked List){
q=Null;
p=s;
while(p!=Null) do {
r=q;
q=p;
p=p➝link;
(q➝link)➝r;
}
s=q;
}