Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e984055

Browse files
author
Ram swaroop
committed
printList in reverse done
1 parent 99407a3 commit e984055

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/me/ramswaroop/linkedlists/ReverseList.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ public SingleLinkedNode<E> recursiveReverseList(SingleLinkedNode<E> node) {
5151
return node;
5252
}
5353

54+
/**
55+
* Recursive method to PRINT the linked list in reverse.
56+
* <p/>
57+
* NOTE: It doesn't reverse the linked list but just PRINTS
58+
* them in reverse.
59+
*
60+
* @param node
61+
* @param <E>
62+
*/
63+
public static <E extends Comparable<E>> void printListInReverse(SingleLinkedNode<E> node) {
64+
if (node == null) return;
65+
66+
printListInReverse(node.next);
67+
68+
System.out.print(node.item + ",");
69+
}
70+
5471
public static void main(String a[]) {
5572
ReverseList<Integer> linkedList = new ReverseList<>();
5673
linkedList.add(11);
@@ -63,5 +80,6 @@ public static void main(String a[]) {
6380
linkedList.printList();
6481
linkedList.recursiveReverseList(linkedList.getNode(0));
6582
linkedList.printList();
83+
printListInReverse(linkedList.getNode(0));
6684
}
6785
}

0 commit comments

Comments
 (0)