IntListSorted - // front of the list. int tmp; for (int i =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
package lab10; p public class IntListSorted extends IntList{ p public IntListSorted() { super(); } /** Add the new item not at end of the list, but at the correct spot so that the list stays sorted. @param newItem Item to add. */ public void add(int newItem) { // Ask the superclass to insert the item at the end of the list. super.add(newItem); // Now, look at the item right before the new item. Is it greater than // the new item? If so, swap the items. Keep doing this until we either // see an item before the new item that is not greater or we hit the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // front of the list. int tmp; for (int i = size - 1; i > 0 && list[i - 1] > list[i]; --i) { tmp = list[i]; list[i] = list[i - 1]; list[i - 1] = tmp; } } public int getMaximum(){ int max = list[size -1]; return max; } public int getMinimum(){ int min = list[0]; return min; } public int getMedian(){ if(size % 2 == 0){ return list[(size/2) - 1]; } else{ return list[(int) Math.ceil(size/2.0)]; } } }...
View Full Document

This note was uploaded on 09/20/2011 for the course COM SCI 227 taught by Professor Staff during the Spring '11 term at Iowa State.

Ask a homework question - tutors are online