Computer Science 61B - Spring 1998 - Hilfinger - Midterm 1

# Computer Science 61B - Spring 1998 - Hilfinger - Midterm 1...

This preview shows pages 1–3. Sign up to view the full content.

CS 61B, Midterm #1, Spring 1998 CS 61B Midterm #1 Spring 1998 Throughout this test, assume that the following definition is available. (It is taken from the lecture notes and are duplicated here for your convenience. There is nothing new here.) class List { public Object head; /* First element. */ public List tail; /* Rest of list. */ public List (Object head, List tail) { this.head = head; this.tail = tail; } } Problem #1: [6 points] Fill in the bodies of the following functions to agree with their comments. Both of these functions select an evenly spaced subsequence of a list. For example, if L is a list containing the strings "aardvark", "basilisk", "axolotl", "gibbon", "gnu", "kumquat", "grapefruit", "kiwi", "poplar" then both subseq1(L, 1, 3) and subseq2(L, 1, 3) return "basilisk", "gnu", "kiwi" a. [3 points] /** A List consisting of elements I, I+K, I+2K, . .. of L, numbering * from 0. If I is greater than or equal to the length of L, the * result will be the empty list. Requires I>= 0, K>0; throws * IllegalArgumentException otherwise. Does NOT modify any of the * List objects in the original list pointed to by L. */ static List subseq1(List L, int i, int k) { //FILL THIS IN (about 8 lines) file:///C|/Documents%20and%20Settings/Jason%20Rafte. ..Spring%201998%20-%20Hilfinger%20-%20Midterm%201.htm (1 of 7)1/27/2007 6:33:01 PM

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

View Full Document
CS 61B, Midterm #1, Spring 1998 } b. [3 points] For this version, do not use the new operator or in any other way allocate new List objects. static List subseq2(List L, int i, int k)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

Computer Science 61B - Spring 1998 - Hilfinger - Midterm 1...

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

View Full Document
Ask a homework question - tutors are online