Section6Key 4 - 13 One possj-ble solution appears below public removeEvens Linkedlntlist Linkedf ntList resu,l-t new LinkedlntList(front null if

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: 13. One possj-ble solution appears below. public removeEvens ( ) { Linkedlntlist () ; Linkedf ntList resu,l-t new LinkedlntList (front !- null) if { result.front frontr' front front.nexti ListNode current front; ListNode resultlast result.front; (current while !- nuLl && current.next !: current.next; resultLast.next : current.next; resultlast next current . next. next; current. = current.next; current i resultlast . next nuIl; ) return result ; ) L4. One possible public if solution appears below. { O; nulI) { ". Iow, int void removeRange (int high) (l-ow throw new IllegalArgumentException (low :: if 0) (high while front front. next; high--; ) else { f ront; Listtlode current int count L; whil-e (count < low) { current. next; current count ++; ) : current.next; ListNode current2 (count while current2 current2.next; count**; ) current. next : current2. nexti ) solution appears beLow. ) 15. One possibl-e public if voi-d doubleI,ist Ot r- nuLl) (front { ListNode hal-f2 : new ListNode(front.data); ListNode back : half2i front; ListNode current (current.next while !- null) { current current . next; back. next : new ListNode (current. data) ; back back. next; -- ) . r iext- : h aTf2 ; c riiienr l_ ...
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