Section6Problems 1

# Section6Problems 1 - CSE143 Section For Lhese public ^..h1...

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE143 Section For Lhese public ^..h1 #6 Problems using the standard ListNode class: problems, class ..1 ^ assume that ( next, we are ListNode ; - .^..t data; ListNode r,uvrlu public // // daLa link in this node stored node in the to next list public ListNode O this (0, null); ) t public ListNode (int data) nuII); this (data, ) public ListNode this . data this . next i ) (int data, data i next; { ListNode next) i "' we are writing methods for a class called And that front: data field of type ListNode called single public cl-ass LinkedlntList private ListNode front; <methods> ) In 1. solving these problems, you may not call any { Linkedlntlist that has a other methods of of the class. If Write a method min is empty, the list returns that the minimum value in a List it shoul-d throw an IllegalStateException. inteqers. 2. whether or not a list returns Write a method hasTwoConsecutive that of (returning numbers that integers has two adjacent are consecutive integers For example, if exists and returning faLse otherwise) . if such a pair true the following sequence of values: stores a varj-abl-e cal-Ied list , then the Iist 18, caLl: . hasTwoConsecutive () l-ist contains numbers. lf 40, the adjacent instead the numbers (1, B) l-ist had stored 2,'7, 8, 39, 18, 40] true because the shouLd return which are a pair of consecutive sequence of values: this [1, 18, I7, 2, J, 39, 18, B] return faLse. This sequence contaj.ns some pairs then the method should of (e.9., numbers that could represent integers 1 and 2, ? and 8, consecutive 39 and 4Or, but those pairs of numbers are not adjacent in the sequence. of adjacent The l-ist also has a pair numbers (18, I1) that are not in the riahr nrrror to be considered q consecutlve: Yog mqL_no! *rlrg}g_ ny aqs_q\$p!i_oqs __ about how manv el-ements aie in the f :-st. 3. Write that returns a method isSorted true if (nondecreasing) and that returns false order considered to be sorted. the list is otherwise. in sorted An empty list is ...
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