This is in PHP
function reverseLinkedListRecursive($current, $second){
if($second->next == null){
$second->next = $current;
return $second;
}
else {
$node = reverseLinkedListRecursive($second, $second->next);
$second->next = $current;
return $node;
}
}
1
Sigiloso
1 de jan. de 2013
//If additional buffer is allowed then use a Stack.
1) iterate through the linked-list and add each node values to a stack,
2)iterate again through the linked-list and replace the node values with the values of the stack(starting from top of the stack )using pop operation.