Sp04m2soln - i++) temp = temp.getNext() result =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Cs 307 Spring 2004 Midterm 2 1 A.4 B.5 4 3 2 1 0 -1 C.7 5 3 1 -1 1 3 5 7 D.37 E.O(N) F.3N^2 + 4N + 3 G.O(N^2) H.O(N) I.O(NlogN) J.O(N^4) K.8 sec L.800 / 19 sec M.4 3 2 1 0 N.8 6 4 O.11 8 2 20 2 soln 1: Object temp Iterator it = items.iterator() while( it.hasNext() ) {temp = it.next() if( target.equals( temp ) ) it.remove() } soln 2: Object temp int i = 0 while( i < items.size() ) {temp = items.get(i) if( target.equals(temp)) items.remove(i) else i++ } soln 3: while( items.indexOf(target) != -1 ) {items.remove( items.indexOf( target ) ) } soln 4: (Gacky) Object temp for(int i = 0 i < items.size() i++) {temp = items.get(i)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 if(target.equals(temp)) {items.remove(i) i-- } } 3. Object result if(iMySize == 1) {result = myTail.getData() myHead = null myTail = null } else {Node temp = myHead for(int i = 0 i < iMySize - 2
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i++) temp = temp.getNext() result = myTail.getData() myTail = temp myTail.setNext(null) } iMySize--return result 4 land[row][col] = 4 helper(land, row, col) private void helper(int land, int row, int col) {//base cases: out of bounds, clear, or burnt out -&gt; do nothing if( row &gt;= 0 &amp;&amp; row &lt; land.length &amp;&amp; col &gt;= 0 &amp;&amp; col &lt; land[0].length &amp;&amp;land[row][col] != 0 &amp;&amp; land[row][col] != -1 ) {double rand = Math.random() { boolean burns = (land[row][col] == 4) || (land[row][col] == 1 &amp;&amp; rand &lt; 0.25) || ( (land[row][col] == 2 || land[row][col] == 3) &amp;&amp; rand &lt; 0.5) ) if( burns ) {land[row][col] = -1 helper(land, row - 1, col) helper(land, row, col + 1) helper(land, row + 1, col) helper(land, row, col - 1) } } }...
View Full Document

This note was uploaded on 11/30/2010 for the course CS 307 taught by Professor Scott during the Spring '08 term at University of Texas at Austin.

Page1 / 2

Sp04m2soln - i++) temp = temp.getNext() result =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online