Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify this code to include another method, called merge (We will work on this problem during this week). The method merge merges two SortedIntList objects

Modify this code to include another method, called merge (We will work on this problem during this week). The method merge merges two SortedIntList objects into one SortedIntList one and returns it.

Here's the original code:

// IntList.java

//

// An (unsorted) integer list class with a method to add an

// integer to the list and a toString method that returns the contents

// of the list with indices.

//

// ****************************************************************

public class IntList

{

protected int[] list;

protected int numElements = 0;

//-------------------------------------------------------------

// Constructor -- creates an integer list of a given size.

//-------------------------------------------------------------

public IntList(int size)

{

list = new int[size];

}

//------------------------------------------------------------

// Adds an integer to the list. If the list is full,

// prints a message and does nothing.

//------------------------------------------------------------

public void add(int value)

{

if (numElements == list.length)

System.out.println("Can't add, list is full");

else

{

list[numElements] = value;

numElements++;

}

}

//-------------------------------------------------------------

// Returns a string containing the elements of the list with their

// indices.

//-------------------------------------------------------------

public String toString()

{

String returnString = "";

for (int i=0; i

returnString += i + ": " + list[i] + " ";

return returnString;

}

}

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago