Princeton University |
Computer Science 441 |
The following are interfaces for singly and doubly-linked nodes and a linked list:
// Interface for node objects w/ values of type String public interface NodeIfc<T>{ // Returns following node. T getNext(); // Hook up newNext to the right of this void setNext(T newNext); // Returns value stored in node String getValue(); // Sets value stored in node to newVal void setValue(String newVal); } ----------------------------------------- // Interface for doubly-linked node objects w/ values of type String public interface DbleNodeIfc<T> extends NodeIfc<T>{ // Returns preceding node. T getPrevious(); // Set node bfore this to be newPrevious void setPrevious(T newPrevious); } ----------------------------------------- // Interface for Ordered List of Strings, parameterized by the type of node. import java.util.Enumeration; public interface OrdListIfcN< implements NodeIfc<N>>{ // Return true iff val is in list boolean inList(String val); // Add newNode to list (in proper order). Duplicates are OK. void add(N newNode); // Return an Enumeration which will go through all elements of list in order. Enumeration getEnumerator(); // If val is in list, delete first copy and return true, else return false. boolean delete(String val); }
// Return Enumeration which goes through elements of list in reverse order. public Enumeration getRevEnumerator();
You will also have to override methods add and delete to ensure that the tail instance variable gets overridden properly. See if you can write them so that you call the inherited method from the superclass and then simply execute a few extra instructions to make sure that tail has the proper value.
For the following problems, please refer to CellClass from the lecture notes as well as the following subclass:
class ColorCellClass inherit CellClass{ color: ColorType; getColor(): ColorType {return self.color} set(nuVal:int): void {x := nuVal; self.color := red;} }Thus in the subclass, setting a cell to a different value changes its color to red.
cell.bump();Your answer should include a description of the use of existentials, the suite of methods (meth and meth'), and the detailed definition of the bump translation given in the lecture notes.