Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9306233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:07:35+00:00 2026-06-19T00:07:35+00:00

Would appreciate any help with this. Am first year programming student and this is

  • 0

Would appreciate any help with this. Am first year programming student and this is a homework assignment to look at recursion.
1. we had to build an arraylist recursively (done below and working for smallest problem and then higher)
2. test it using a harness (also below)
3. we then have to make a clone copy of the array list (which I think is working) and write a method to recursively reverse the arraylist and include it in the ListMethodRunner test; this is where I am stuck. I have included my code below which is brining up an error on ‘list = reverseList(list.remove(0));’ in the reverseList Method. Any suggestions where Im going wrong?

//List Methods
import java.util.*;

public class ListMethods
{
//new method that produces an array list of integers (tempList) based on input of int n
public static ArrayList<Integer> makeList(int n)
{
  ArrayList<Integer> tempList = null;
  if (n <= 0)  // The smallest list we can make
  {

      tempList = new ArrayList<Integer>(); // ceate the list tempList
      return tempList;                      //return blank list for this if statement

  }
  else        // All other size lists are created here
  {

      tempList = makeList(n-1); //recursively go through each variation of n from top down, when reach 0 will create the list
      tempList.add(n); // program will then come back up through the variations adding each value as it goes

  }
  return tempList; //return the tempList population with all the variations

   }

//create a copy of the values in the array list (tlist) and put it in (list)- used in next method
public static ArrayList<Integer> deepClone(ArrayList<Integer> tList)
{
   ArrayList<Integer> list = new ArrayList<Integer>();
   for (Integer i : tList)
   {
       list.add(new Integer(i));
    }
    return list;
}
//method that creates arraylist
   public static ArrayList<Integer> reverseList(ArrayList<Integer> tList)
  {
   ArrayList<Integer> list = ListMethods.deepClone(tList);
 if (list.size()<=1)    // The list is empty or has one element
   {
      return list;// Return the list as is – no need to reverse!
 }
 else
 {
   list = reverseList(list.remove(0)); //recurse through each smaller list 
                                        //removing first value until get to 1 and will create list above
   list.add(0);
  // Use the solution to a smaller version of the problem
 // to solve the general problem
 }
 return list;
 }
}

//List  Methods Runner


import java.util.ArrayList;

public class ListMethodsRunner
{
 public static void main(String[] args)
{
  ArrayList<Integer> tempList = ListMethods.makeList(100);
  if (tempList.size() == 0)
  {
      System.out.println("The list is empty");
  }
  else
  {
     for (Integer i : tempList)
     {
        System.out.println(i);
     }
  }

     }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T00:07:37+00:00Added an answer on June 19, 2026 at 12:07 am

    Replace

    list = reverseList(list.remove(0))
    

    With

    list.remove(0);
    list = reverseList(list);
    

    ArrayList::remove(int) returns the element that was removed from the list. (type Integer in this case)

    reverseList needs an ArrayList<Integer> as parameter. Ergo the error.

    You also have to store the element before inserting it again. Your code should look like this:

    Integer num = list.remove(0);
    list = reverseList(list); 
    list.add(num);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would appreciate any help on this issue. Lets say I want to load
I'm relatively new to Java and would appreciate any help on this! I have
Any help with this problem would be fantastic. I appreciate all contributions! Let us
Hi I'm having some problems making my function structure. Would appreciate any help. First
I'm quite new at this and would really appreciate any help on this. I'm
Would appreciate any help with this.:) I have the following text file: roomA Springer,
Any help here would be greatly appreciated. I have this table hospital Nurse |
I would really appreciate any help with the following problem: I need to be
Would very much appreciate any help or hint on were to go next. I'm
I would really appreciate any jquery expert help as a method I've used previously,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.