Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use JAVA language. public class DynamicArray2 { private String[] data; // the backing array private int virtualArrayLength; // the number of elements in the dynamic

Use JAVA language.

public class DynamicArray2 {

private String[] data; // the backing array

private int virtualArrayLength; // the number of elements in the dynamic array

// Throws an IndexOutOfBoundsException if i is not a valid index

// for adding to the dynamic array, otherwise inserts s at index i.

// Elements can be added from index 0 to this.size().

public void add(int i, String s) {

// If there is no room for s in data, create a new array

// that is twice as long as data. Copy the contents of data

// over to this new array. Set data (the reference to the

// backing array) to this new array.

// Shift the items in data at indexes starting at i up by one,

// to make room for s at index i.

// HINT: Try this on paper first

// Add s at index i.

// Update virtualArrayLength.

// (DO NOT create a new array each time this method is called.

// Do so ONLY when the capacity of data in the backing store is exceeded,

// which will happen infrequently.)

}

// Throws an IndexOutOfBoundsException if i is not a valid index

// of the dynamic array, otherwise removes the element at index i

// and shifts the elements after i down one to fill in the gap.

public void remove(int i) {

// DO NOT create a new array anywhere in this method.

// Instead, shift the items in data from indexes i+1 on

// down by one, to overwrite the "removed" string at index i.

}

}

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago

Question

1. Signs and symbols of the map Briefly by box ?

Answered: 1 week ago