@@ -0,0 +1,1223 @@
+package data_structures.linked_lists;%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0A%0D%0A/*%0D%0A * Problem Statement:%0D%0A * You are given the pointer to the head node of a linked list and you need to%0D%0A * print all its elements in reverse order from tail to head, one element per%0D%0A * line. The head pointer may be null meaning that the list is empty - in that%0D%0A * case, do not print anything!%0D%0A * %0D%0A * Input Format:%0D%0A * You have to complete the void ReversePrint(Node* head) method which takes one%0D%0A * argument - the head of the linked list. You should NOT read any input from%0D%0A * stdin/console.%0D%0A * %0D%0A * Output Format:%0D%0A * Print the elements of the linked list in reverse order to stdout/console%0D%0A * (using printf or cout) , one per line.%0D%0A * %0D%0A * Sample Input: %0D%0A * 1 --%3E 2 --%3E NULL%0D%0A * 2 --%3E 1 --%3E 4 --%3E 5 --%3E NULL%0D%0A * %0D%0A * Sample Output: %0D%0A * 2%0D%0A * 1%0D%0A * 5%0D%0A * 4%0D%0A * 1%0D%0A * 2%0D%0A */%0D%0Apublic class PrintInReverse %7B%0D%0A%0D%0A%09void ReversePrint(Node head) %7B%0D%0A%0D%0A%09%09if (head != null) %7B%0D%0A%09%09%09ArrayList%3CInteger%3E array = new ArrayList%3C%3E();%0D%0A%09%09%09Node runner = head;%0D%0A%09%09%09while (runner != null) %7B%0D%0A%09%09%09%09array.add(runner.data);%0D%0A%09%09%09%09runner = runner.next;%0D%0A%09%09%09%7D%0D%0A%09%09%09for (int i = array.size() - 1; i %3E= 0; i--) %7B%0D%0A%09%09%09%09System.out.println(array.get(i));%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%7D

Add PrintInReverse