Programming and Problem Solving with Java

(やまだぃちぅ) #1
11.3 S o rting the List Items | 541

Class ListWithSort


We are now ready to code our derived class. In the documentation, we need to include a
note stating that the alphabetic order may be lost with future insertions.


public classListWithSort extendsList
{
// The items in the list can be rearranged into ascending order
// This order is not preserved in future insertions


publicListWithSort()
{ // Default constructor
super();
}

publicListWithSort(int maxItems)
{ // Constructor
super(maxItems);
}

publicvoid selectSort()
// Arranges list items in ascending order;
// selection sort algorithm is used

Contents of

y goes into x


Contents of

x goes into temp


Contents of temp


goes into y


x


y temp


2 1


3


Figure 11.5 Swapping the Contents of Two Variables,xand y

Free download pdf