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
class Node
rev data; Node next;
Node(rev d) {
data = d; next = null; } } void Reverse(Node
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
Get step-by-step solutions from verified subject matter experts
