既然是单向链表,所以不可避免的一定是从前向后遍历。逆向输出的过程,可以看做是“找下一个”的重复操作,直到下一个是null。所以一定可以用递归来解决。
当然如果利用栈来解决也是可以的。
当然如果利用栈来解决也是可以的。
public static void ReverseOutput(LinkedNode head){
if(head == null)
return;
if(head.next == null)
System.out.print(head.data+" ");
else{
ReverseOutput(head.next);
System.out.print(head.data+" ");
}
}