Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CS 2 5 1 Program 0 5 Main topics: Arrays ArrayLists Program Specification: An array that can grow and shrink ( as needed ) at
CS
Program
Main topics: Arrays
ArrayLists
Program Specification:
An array that can grow and shrink as needed at run time is generally called a dynamic array. You are to write a class named DynArray which can hold double values that adheres to the following:
The physical size of the array at all times is a nonnegative power of two smallest of which is
The physical size is never more than times the number of elements which occupy it with exception to when it is at size
Mandatory Instance variables:
private double array;
private int size;
private int nextIndex;
Mandatory Instance methods:
public DynArray constructor
set array to a nes array of double, of size one
set size to one,
and set nextIndex to zero.
public int arraysize accessor
return the value of size.
public int elements accessor
return the value of nextIndex.
public double at int index accessor
if index nextIndex
return the value of arrayindex
else
return Double.NaN.
private void grow
make array a reference to an array that is twice as large
and contains the same values for indicies through
nextIndex and adjust size appropriately.
private void shrink
make array a reference to an array that is half as large
and contains the same values for indicies through
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started