



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




class SelectionSorter { public SelectionSorter(String[] anArray) { array = anArray; } public void sort() { for (int i = 0; i < array.length - 1; i++) { int minPos = minimumPosition(i); swap(minPos, i); } } private void swap(int i, int j) { String temp = array[i]; array[i] = array[j]; array[j] = temp; } private String[] array; }
2
Part 2: Binary Search
public class BinarySearcher { public BinarySearcher(int[] anArray) { array = anArray; } public int search(int v) { int low = 0; int high = array.length - 1; while (low <= high) { int mid = (low + high) / 2; int diff = array[mid] - v; } return -1; } private int[] array; } if (diff == 0) return mid; else if (diff < 0) high = mid + 1; else low = mid - 1;
Part 4: Implementing a Linked List class Term { Term(int coeff, int expon) { coefficient = coeff; exponent = expon; } public int compareTo(Term T2) { return new Integer(exponent).compareTo( new Integer(T2.exponent)); } int coefficient, exponent; Term link; } class Polynomial { void addTerm( Term T ) { } Term find(Term T) { } public String toString() { } // this is the only instance field Term lstHead = new Term(0,0); }
void addTerm(Term T) { }
Term find(Term T) { }