如何交換鏈表的最後兩個節點?我試圖使用一個輔助節點,因爲我認爲這是需要避免的過程中「丟失」的一個節點......交換單鏈表的最後兩個節點
...
Node node3 = new Node("Hi", null) ;
Node node4 = new Node("Hello", null) ;
...
// swap node3 & node4
Node temp = node3.succ ;
node3.succ = null ; // this should be the last node now, so i set its pointer to null
node2.succ = temp ; // the second's node successor becomes what used to be the last node
temp = node4 ; // not sure how to use temp here. what should it point to if at anything?
我覺得我這樣做不對,任何提示?
非常感謝你! – raoulbia