MidtermSolution

MidtermSolution - s.addInOrder list1.get i return s Problem...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 Midterm #1 Solution CS20, Spring 2004 Problem 1: int compareTo( Object other) where the result: < 0 if this less than other = 0 if this = other > 0 if this > other Problem 2: String, Number, Integer, Float, Student, Name,. .. Not: Object Problem 3: String getMajor( ) void setMajor( String m ) Problem 4: gamma alpha delta Problem 5: There are many solutions. The most straightforward: // Assume the list is L. Object temp7 = L.remove( 7 ) Object temp3 = L.remove( 3 ) L.add(3, temp7) L.add(7, temp3) A solution requiring no temporary storage: L.add(7, replace(3, remove(7) ) ) L Problem 6: //Declarations: SimpleOrderedList s = new MyLinkedList( ) // plus any others you need for your particular code. //Code: for (int i = 0 i < len
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { s.addInOrder( list1.get( i ) ) } return s Problem 7: a) 2 & 5 (or 3 & 6 ) b) all others not given in part a) Problem 8: a) 2 & 6 (or 3 & 5 ) b) all others not given in part a) Problem 9: class Node { private Object data Sheet1 Page 2 private Node next private Node( Object dataPortion ) { data = dataPortion next = null } // end constuctor private Node( Object dataPortion, Node nextNode ) { data = dataPortion next = nextNode } // end constuctor // set and get methods are good, but not required for credit if constructors set both values. } // end Node Problem 10: first.next.next.next Problem 11: 27 Problem 12: 7 5 3 * 2 / + 2 ^ Sheet1 Page 3 i++ ) Sheet1 Page 4...
View Full Document

This note was uploaded on 04/08/2008 for the course CS 20 taught by Professor Agrawal during the Spring '08 term at UCSB.

Page1 / 4

MidtermSolution - s.addInOrder list1.get i return s Problem...

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

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