732
publicListWithSort()
{
super();
}
publicListWithSort(intmaxItems)
{
super(maxItems);
}
public voidselectSort()
// Arrange list items into ascending order;
// selection sort algorithm is used.
{
String temp; // Temporary variable
intpassCount; // Loop control variable for outer loop
intsearchIndex; // Loop control variable for inner loop
intminIndex; // Index of minimum so far
for(passCount = 0 ; passCount < numItems - 1 ; passCount++)
{
minIndex = passCount;
// Find the index of the smallest component
// in listItems[passCount]..listItems[numItems - 1]
for(searchIndex = passCount + 1 ; searchIndex < numItems;
searchIndex++)
if(listItems[searchIndex].compareTo(listItems[minIndex]) < 0 )
minIndex = searchIndex;
// Swap listItems[minIndex] and listItems[passCount]
temp = listItems[minIndex];
listItems[minIndex] = listItems[passCount];
listItems[passCount] = temp;
}
}
}
- a.public abstract classListWithDuplicates
{
protectedString[] listItems; // Array to hold list items
protected intnumItems; // Number of items in the list
protected intcurrentPos; // State variable for iteration