2- Given following data structures of a double linked list :
class ListNode
{
String info ;
ListNode prev ;
ListNode next ;
…….
}
Write a Java method which prints the content of double linked list in reverse order.
/* passing the head of the list
*/
public static void print_reverse(ListNode head)
{
ListNode temp = head;
/* go to the last node
of the ListNode */
while (temp.next != null) {
temp =
temp.next;
}
/* Print node and keep
on coming back */
while (temp.prev != null) {
System.out.println(temp.info + "\t");
temp =
temp.prev;
}
}
Get Answers For Free
Most questions answered within 1 hours.