public Node reverse(Node list)
{
if (list == null || list.next==null) return list;
Node nextItem = list.next;
list.next = null;
Node reverseRest = reverse(nextItem);
nextItem.next = list;
return reverseRest;
}

Advertisements