project 1 instructions part 1 design and implement a generic stack class stackumuc a 5210680
Project 1 |
Instructions Part 1 |
Design and implement a generic stack classStackUMUC and a generic queue class QueueUMUC (these names are chosen as to avoid confusion with similar classes defined in JDK).
For StackUMUC class, implement the following methods:
StackUMUC(int) // class constructor
void push(T)
T pop()
T peek()
String toString()
For QueueUMUC class, implement the following methods:
QueueUMUC(int) // class constructor
void put(T)
T get()
T peek()
String toString()
The source code of the two classes should compile without errors.
Project 2 |
Instructions |
Part 1 – Design and implement a binary tree using generics
Design and implement a generic binary tree consisting of classes BT and BTnode and the interface BTinterface.
The class BT defines the instance variable root of type BTnode, a default constructor which builds an empty tree and implements the methods specified by the interface BTinterface.
The class BTnode defines the instance variable value of type T, the instance variables left and right of type BTnode representing references to the left and right child nodes, a constructor with parameter representing the value of the new node and a method getValue returning the node value.
If necessary, additional instance variables and methods could be added to the classes BT and BTnode (explanation should be provided for these extra resources).
The interface BTinterface specifies the following methods that will be implemented by the class BT using recursive techniques:
– inorder, preorder, postorder for tree traversal – these methods should return the corresponding string representation of the tree;
– insertLeftChild, insertRightChild – these methods take the value of the new node and the value of its parent node as parameters and return a reference to the new inserted node.
– isMember – takes the value as parameter and returns the reference to the node containing the specified value or null is the value is not in the tree.
– isLeaf – takes the value as parameter and returns true if the node containing that value is a tree leaf and false otherwise.
– getMaxLevels – returns the maximum number of tree levels.
– getNumberOfNodesAtLevel – returns the number of nodes located at a specified level;
– getTotalNumberOfTreeNodes