




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





CS61B, Fall 2001, Test #2, Prof Hilfinger
f. a and c
b. (A): i0.hasNext() || i1.hasNext(); (B): if (! i0.next().equals(i1.next()) return false; (C): i0.hasNext() || i1.hasNext(); c. (A): i0.hasNext() && i1.hasNext() && !i0.next().equals(i1.next()) (B): /* Empty statement*/ (C): i0.hasNext()? false : !i1.hasNext() d. (A): i0.hasNext() && i1.hasNext(); (B): if (! ((String) i0.next()).equals((String)i1.next())) return false; (C): !i0.hasNext() && !i1.hasNext(); e. all of the above f. a and c g. a, c, d h. a and d i. none of the above
B. Which of the following works as a replacement for (D)? a. !nodes.isEmpty() b. nodes.size()> c. nodes.size()> d. nodes.peek() = =null e. a and b f. none of the above
C. Which of the following works as a replacement for (E)? a. (TreeNode) nodes.peek(); b. nodes.peek(); c. nodes.pop(); d. all of the above e. a and b f. none of the above
D. Which of the following work as replacements for (F) and (G)? a. (F): if (r.child0 != null) nodes.push (r.child0); (G): if (r.sib != null) nodes.push(r.sib); b. (F): if (r.sib != null) nodes.push(r.sib); (G): if (r.child0 != null) nodes.push(r.child0); c. (F): if (r.child0 != null ) nodes.push(r.child0); (G): for (TreeNode p =r.sib; p!=null; p=p.sib) nodes.push(p); d. (F): for (TreeNode p=r.sib; p!=null; p=p.sib) nodes.push(p); (G): if (r.child0!=null) nodes.push (r.child0); e. all of the above
f. a and c g. b and d h. none of the above
String S1 = "Hello, world", S2 = "Hello, ", S3 = "world", S4 = S2+S3, S5 = S4;
Which of the following are true? a. S4= =S b. S4.equals(S1) c. S5= =S d. S4= =S2 + S e. all of the above f. b and c g. b, c, d h. none of the above
/** A section of a drawing. A Component contains >=0 subcomponents. / public (A) class Component { /* A Component at location (X, Y) on the screen / public Component (int x, int y) {this.x=x; this.y=y; } /* X and Y coordinates of THIS. */ public int x () {return x; } public int y () {return y; }
/** Draw the picture represented by THIS, not including its subcomponents. */ protected (A) void renderMe () (B)
/** Draw the picture represented by THis, including its subcomponents. */ public void render() { (C) }
/** An iterator returning all subcomponents of THIS. */ public Iterator iterator () {(D); } private int x,y; }
/** A Container serves simply to hold other Components. */
f. a and c g. none of the above
C. Which of the following are valid replacements for (E), in all the places it appears? a. Nothing (leave blank) b. this(x,y); c. super(x,y); d. this.x=x; this.y=y; e. all of the above f. b and d g. c and d h. none of the above
D. Which of the following are valid replacement for (D) and (G)? a. (D): if (this instanceof Container) return subConponents.iterator (); else return Collections.EMPTY_LIST.iterator() (G): subComponents.iterator(); b. (D): if (this instanceof Container) return subComponents.listIterator(); else return Collections.EMPTY_LIST.iterator() (G): subComponents.listIterator(); c. (D): if (this instanceof Container) return ((Container) this).subComponents.iterator(); else return Collections.EMPTY_LIST.iterator() (G): subComponents.iterator(); d. (D): Collections.EMPTY_LIST.iterator() (G): subComponents.iterator(); e. (D): Collections.EMPTY_LIST.iterator() (G): subComponents.listIterator(); f. all of the above g. a and b h. d and e i. c, d, e j. none of the above
static List uniq1 (List L0) { List L = L0; return uniq1a (L, L.size ()-1); }
static List uniq1a (List L, int k) { if (k<=0)
return L; else if (L.get(k).equals(L.get(k-1))) L.remove(k); return uniq1a (L,k-1); }
static List uniq2 (List L0) { if (L0.size()<= 1) return new LinkedList (L0); else if (L0.get(0).equals(L0.get(1))) return uniq2(L0.sublist(1, L0.size())); else { List r=uniq2(L0.sublist(1,L0.size())); r.add(L0.get(0),0); return r; } }
These methods remove adjacent duplicate elements from a list. Which of the following is true? a. uniq1 is non-destructive and uniq2 is destructive. b. uniq1 is destructive and uniq2 is non-destructive. c. both uniq1 and uniq2 are destructive. d. both uniq1 and uniq2 are non-destructive.