Write a recursive void method to display a single-ended singly linked list backwards

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I need some help with this problem. my instructions are "Write a recursive void method to display a single-ended singly linked list backwards. " 

i am using custom code for links and a linked list that comes from my textbook. the textbook is "Data Structures and Algorithms in Java Second Edition" by Robert Lafore 

in my code i made a method called recursiveReverse() which takes two arguments a integer count and an integer sizeOfList is supposed to use a for loop to get the method to where it needs to go on the list using a current and previous link. the current is where the method is at currently and the previous is where the current was before the list iterated. i am having trouble finding a way to get the method to end when the code finally gets to where it needs to be. the code before the first recursion should reach the end of the list and then count should be incremented in the recursion argument. the code presented is still not completely finished but please let me know if i am on the right track and also how i can possibly get this idea to work without any nullpointerexceptions or logical errors.

PLEASE explain this in words and NOT in code.

 

here is the code i have so far.

LINK CODE

public class link
{
public int dData;
public link next;


public link(int dd)
{
dData = dd;

}

public void displayLink()
{
System.out.print(dData);
}
}

LINKED LIST CODE

public class linkedList
{
    private link first;
   
    public linkedList()
    {
    first = null;
    }
    
    public boolean isEmpty()
    {
    return (first==null);
    }
    
    public void insertFirst(int id)
    {
        
    link newLink = new link(id);
    newLink.next = first;
    first = newLink;
    }
    
    
    
    public void recursiveReverse(int count, int sizeOfList)
    {
        link current = first;
        link previous = first;
        
        
        
        for(int i = count; i < sizeOfList; i++)
        {
        if(current.next == null)
        {
        return;
        }
        else
        {
        previous = current;
        current = current.next;
        }
        }
        
        recursiveReverse(count++, sizeOfList);
        
        if(current != first)
        {
        current.displayLink();
        }
        else
        {
        
        }
        
        }
    }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY