Question: Hello Q: Print a singly linked list in reverse order by using recursive algorithm please explain the code : class SingleyLinkedList { Node head; class

Hello

Q: Print a singly linked list in reverse order by using recursive algorithm

please explain the code :

class SingleyLinkedList { Node head;

class Node {

rev data; Node next;

Node(rev d) {

data = d; next = null; } } void Reverse(Node head) { if (head == null) { return; } Reverse(head.next); System.out.print(head.data + " "); }

public void add(rev data) { Node new_node = new Node(data); new_node.next = head; head = new_node; }

public void print() { Node current = head; if (head == null) { System.out.println("List is empty"); } else { do {

System.out.print(" " + current.data); current = current.next; } while (current != null); System.out.println(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!