11.3 S o rting the List Items | 541Class 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 usedContents ofy goes into x
Contents ofx 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