Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Explain why strategic planning is important to all managers.

Answered: 1 week ago