List reverse1(List n){
if(n.isEmpty){
return n;
}
List curr = n.next;
List tail = n;
List temp;
tail.next = NULL;
while(curr != NULL){
temp = curr;
temp.next = tail;
tail = temp;
curr = curr.next;
}
return tail;
} 递归算法
List* reverse2(List *oldList, List newList = NULL){
if(oldList->isEmpty)
return oldList;
List *next = oldList->next;
oldList->next = newList;
newList = oldList;
return (NULL==next)?newList:reverse2(next, newList);
}
转载于:https://blog.51cto.com/no001/1049892