File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
src/me/ramswaroop/linkedlists Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,23 @@ public SingleLinkedNode<E> recursiveReverseList(SingleLinkedNode<E> node) {
51
51
return node ;
52
52
}
53
53
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
+
54
71
public static void main (String a []) {
55
72
ReverseList <Integer > linkedList = new ReverseList <>();
56
73
linkedList .add (11 );
@@ -63,5 +80,6 @@ public static void main(String a[]) {
63
80
linkedList .printList ();
64
81
linkedList .recursiveReverseList (linkedList .getNode (0 ));
65
82
linkedList .printList ();
83
+ printListInReverse (linkedList .getNode (0 ));
66
84
}
67
85
}
You can’t perform that action at this time.
0 commit comments