Section2Key 1 - Solution The variables 89 99 and would...

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solution The variables Iow 09 59 89 99 and would return the would hiqh take mid 4 7 a 9 to CSE143 Section following #2 Problems sequence of values on the value take mid 9. following sequence of values: 2. The variables Iow would hiqh 8 8 6 5 on the 2 o o 7 o 5 -7 . and woul-d return the value No f inal value for mid i-s shown because the loop exits after high is set to 5. The value -7 indicates that the point* for the given value is 6. "insertion rn other wordsr w€ wouLd want to insert the val-ue at index 6 to preserve sorted order. Two possible solutions appear below. The second is first because it is guaranteed to complete its work the data. public void removeAll (int inti:0; (i while (elementDataIi] if remove (i); else i -L+. much faster than the with one pass through value) :- { value) ) public void removeAll (int value) { int newSize - 0; (int for i = 0; i < size; i++1 (elementDatatil if !: value) { elementData InewSize] : elementData newsize++i ) size: newSizei ) 4. One possible solution appears below. Ii] ; public void printfnversions Ot (int j.; i++) for i - O; i < size (int j : i + L; j < size; for j++) (elementDatalil if > elementDatatjl ) System.out.println('r ('r + el_ementDataIi] + + elementDataljl + u)") ww , ...
View Full Document

This note was uploaded on 11/03/2009 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Ask a homework question - tutors are online