Programming and Problem Solving with Java

(やまだぃちぅ) #1

(^560) | Array-Based Lists


{

numItems = 0;
listItems = new Comparable[100];
currentPos = 0;
}

public booleanisFull()
// Returns true if there is no room for another component;
// false otherwise
{
return(listItems.length == numItems);
}

public booleanisEmpty()
// Returns true if there are no components in the list;
// false otherwise
{
return(numItems == 0);
}

public intlength()
// Returns the number of components in the list
{
returnnumItems;
}

public abstract booleanisThere(Comparable item);
// Returns true if item is in the list; false otherwise

// Transformers
public abstract voidinsert(Comparable item);
// If list is not full, inserts item into the list;
// otherwise list is unchanged
// Assumption: item is not already in the list

public abstract voiddelete(Comparable item);
// Removes item from the list if it is there

// Iterator pair
public voidresetList() // Prepare for iteration
{
currentPos = 0;
}
publicComparable getNextItem()
// Returns the item at the currentPos position; resets current
// position to first item after the last item is returned
// Assumption: no transformers have been invoked since last call

T


E


A


M


F


L


Y


Team-Fly®

Free download pdf