Define the methods in each class Concrete class: DArray private int array[] public DArray() [constructor array size
Question:
Define the methods in each class
Concrete class: DArray
private int array[]
public DArray() [constructor array size = 1, nAllocations = 1, nElements = 0]
private void expandA()
--------------------------------
Interface: DArrayBehavior
public void append(int item) [add at the end]
public int getFirstItem()
public int getLastItem()
---------------------------------
Abstract Class: ArrayBP
Protected int numElements
Protected int numAllocations
public abstract void storeAt(int item, int index); public abstract int getFrom(int index);
public abstract int len(); [returns current length] public abstract void remove(); [removes last item] public abstract void removeAt(int index); [removes the item at the given index]
Followings should be implemented
inside the abstract class
public int getNumElements()
public int getNumAllocations()
public void setNumElements(int n)
public void setNumAllocations(int n)
public void increaseNumElements() [increase by 1] public void decreaseNumElements() [decrease by 1]
Dynamic array: Used to append integers in an empty list without creating an array with fixed sizes.
-append(int item) will append the item at the end of the array.
-If array is full, use expandA() to double the capacity.
-remove() will remove the last item, if any
-removeAt(int index) remove the item at index
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba