如何交换链表的最后两个节点?我试图使用一个辅助节点,因为我认为这是需要避免的过程中“丢失”的一个节点......交换单链表的最后两个节点
...
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