package dk.itu.oop.lecture5; public class Exercises{ public static void main(String[] args){ //System.out.println("Kasper".startsWith(null)); String haddock = "You #!@ Miserable earthworms! Numbskulls! and Carpet-sellers!"; toWords(haddock); System.out.println("----------"); WordIterator itr = new WordIterator(haddock); while (itr.hasNext()) System.out.println(itr.next()); System.out.println("----------"); int[] a ={3,6,7,3,8,1,2,5}; bubbleSort1(a); for( int i=0; ia[j]){ int tmp = a[j]; a[j]=a[j-1]; a[j-1]=tmp; } } i--; } } static void bubbleSort2(int[] a){ boolean sorted=false; // sorted iff a is sorted while (!sorted){ sorted=true; // inv: sorted iff a is sorted from 0 to j-1 for (int j = 1; ja[j]){ int tmp = a[j]; a[j]=a[j-1]; a[j-1]=tmp; sorted=false; } } } } } class WordIterator implements OOPIterator{ // inv: if nextWord.size() = 0, the iterator is empty // else nextWord is the head. // i is either N or the first unprocessed letter in str // N is the length of str. final String str; final int N; int i; String nextWord; WordIterator(String str){ this.str= str; i=0; N = str.length(); findNext(); } private void findNext(){ // skip non letters while( i0; } public Object peek(){ return nextWord; } public Object next(){ String ret = nextWord; findNext(); return ret; } public OOPIterator cloneMe(){ try{ return (OOPIterator)super.clone(); }catch(Exception shouldNotHappen){ return null; } } }