

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions to problem 1, 2, and 3 from the cs 61b data structures midterm i exam held in spring 2009. Topics covered include instance variables, class variables, super keyword, inheritance, interfaces, abstract classes, constructor recursion, and removing a node from a linked list.
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


import java.io.*; interface Aaa { public double number(); } abstract class Bbb { public int[][] i; public Bbb(int j) { i = new int[4][6]; i[3][5] = j; } public double number() { return 12.73;
public abstract void cureCancer(); } public class Ccc extends Bbb implements Aaa { public Ccc() { super(2); } public void cureCancer(int i) { this.i[1][1] = 4; } public void cureCancer() { System.out.println(number()); } public static void main(String[] args) { Aaa a = new Ccc(); Bbb b = (Bbb) a; b.i[0][0] = 1; } }
public void removeNode(SListNode node) { if (head == node) { head = head.next; } else { SListNode n = head; while (n.next != node) { n = n.next; } n.next = n.next.next; } }
public void removeNode(SListNode node) { DListNode dnode = (DListNode) node; // Assume this cast always succeeds. super.removeNode(node); if (tail == node) { tail = dnode.prev; } else { ((DListNode) node.next).prev = dnode.prev; } }