請問,關於環狀雙向鏈結串列的一個問題……

5 views
Skip to first unread message

張凱傑

unread,
Mar 23, 2010, 7:06:00 AM3/23/10
to SJ10-Algorithm
請問,為何環狀雙向鏈結串列的頭空節點,其……

右鏈結要指向第一節點而不是最後節點?
左鏈結要指向最後節點而不是第一節點?

如老師的講義裡的圖:
http://i193.photobucket.com/albums/z170/QooJC/Others/Ch04-CDLL-Teacher.png

為何不是這樣鏈結?
http://i193.photobucket.com/albums/z170/QooJC/Others/Ch04-CDLL-Question.png

其他節點都是左鏈結指向前一節點,右鏈結只向下一節點,為何單獨頭空節點相反?

(備註:借用並修改了一下老師講義裡的圖,不好意思)

張凱傑

unread,
Mar 23, 2010, 7:30:27 AM3/23/10
to SJ10-Algorithm
再問一個問題。請問老師的講義中,含頭空節點的環狀雙向鏈結串列在沒有任何資料,也就是只有頭空節點一個節點時,其左與右鏈結都是「指向自己」嗎?
圖:http://i193.photobucket.com/albums/z170/QooJC/Others/Ch04-CDLL-
NullHead.png

若是的話,請問其初始化的程式碼是否為以下?

//CDLLPtr:存取指標。
//CDLLHead:頭空節點。

//環狀雙向鏈結串初始化。
void CircleDLL()
{
CDLLPtr = CDLLHead;

CDLLPtr -> LLink = CDLLPtr;
CDLLPtr -> RLink = CDLLPtr;

return;
}

Message has been deleted

張凱傑

unread,
Mar 23, 2010, 7:33:43 AM3/23/10
to SJ10-Algorithm
上面的圖的超連結沒貼好,再貼一次:
http://i193.photobucket.com/albums/z170/QooJC/Others/Ch04-CDLL-NullHead.png

Shyong Jian Shyu

unread,
Mar 23, 2010, 12:40:34 PM3/23/10
to sj10-al...@googlegroups.com
凱傑:
 
兩種方式皆可, 寫程式時保持一致即可;
倒是第二種方式也許比較直覺~~
 
S. J.

To unsubscribe from this group, send email to sj10-algorithm+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Reply all
Reply to author
Forward
0 new messages