Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 (covers: Recursion, ArrayLists) The purpose of this question is to write a complete Java program that prints the content of an ArrayList recursively

Question 2 (covers: Recursion, ArrayLists) The purpose of this question is to write a complete Java program that prints the content of an ArrayList recursively and deletes duplicates from the ArrayList recursively. Modify the file named TestA5Q2.java that must be downloaded from Moodle. Most of the solution has been written. Complete the methods described below to have a complete working program. Complete the method that begins with the following header. public static void displayIntegers(String heading, ArrayList integers) This method is given a heading to print and the ArrayList to print recursively. Print the heading, followed by "<< " on a new line. Call the recursive method with the same name as this method (described below) to recursively print the values of the elements in the array on the same line. Then print ">>" on the same line as the elements. See the sample run of the program for the exact format of the output. Complete the method that begins with the following header. public static void displayIntegers(ArrayList integers, int position) This method is given the ArrayList for which an element is to be printed and the position of the element to print. Print the element at the given position and recursively call this method to print the next element in the ArrayList until there are no more elements left to print. Complete the method that begins with the following header. public static void deleteLastDuplicates( ArrayList integers, int position) This method is given an ArrayList and the position of the element for which the last duplicate is to be deleted, and deletes the last duplicate of the element at that position. Hint: Use the lastIndexOf method. The original element remains in the ArrayList. The method calls itself recursively to delete the last duplicate of the next element in the ArrayList. Complete the method that begins with the following header. public static void deleteAllDuplicates( ArrayList integers, int position) This method is given an ArrayList and the position of the element for which all duplicates are to be deleted, and deletes all duplicates of the element at that position. The original element remains in the ArrayList. This is a small change to the previous method, only one statement that recursively calls this method needs to be added. A sample run of the program is shown on the next page. Your output must match the sample output as closely as possible. --------------------------------------------- Assignment 5 COMP 1020 Winter 2018 Page 7 of 7 Before deleting last duplicates. << 100 200 200 300 400 300 100 500 500 400 100 400 100 100 >> --------------------------------------------- After deleting last duplicates. << 100 200 300 400 100 500 400 100 >> --------------------------------------------- Before deleting all duplicates. << 100 200 200 300 400 300 100 500 500 400 100 400 100 100 >> --------------------------------------------- After deleting all duplicates. << 100 200 300 400 500 >> Programmed by Stew Dent. Date: Friday Mar 23 09:34:21 CST 2018 End of processing. Hand in your complete program.

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

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions