1 public LinkNode Reverse(LinkNode node) 2 { 3 if (node.next == null) 4 return node; 5 6 var prevNode = Reverse(node.next); 7 8 var temp = node.next; 9 10 temp.next = node;11 12 node.next = null;13 14 return prevNode;15 }
//非递归 public LinkNode Reserve(LinkNode node) 2 { 3 LinkNode prev = null; 4 LinkNode next = null; 5 6 while (node != null) 7 { 8 next = node.next; 9 10 node.next = prev;11 12 prev = node;13 14 node = next;15 }16 return prev;17 }