Generic BinaryTree & Stack Solution

Topsolutions
 (Not rated)
 (Not rated)
Chat

 

Project 1

Instructions

Part 1

Design and implement a generic stack classStackUMUC<T> and a generic queue class QueueUMUC<T> (these names are chosen as to avoid confusion with similar classes defined in JDK).

For StackUMUC<T> class, implement the following methods:

StackUMUC(int)    // class constructor
void push(T)
T pop()
T peek()
String toString()

For QueueUMUC<T> 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<T> and BTnode<T> and the interface BTinterface<T>. 

The class BT<T> defines the instance variable
 root of type BTnode<T>, a default constructor which builds an empty tree and implements the methods specified by the interface BTinterface<T>. 

The class BTnode<T> defines the instance variable
 value of type T, the instance variables left and right of type BTnode<T>  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<T> and BTnode<T> (explanation should be provided for these extra resources).

The interface BTinterface<T> specifies the following methods that will be implemented by the class BT<T> 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

 

 

    • 10 years ago
    Complete A++ Solution
    NOT RATED

    Purchase the answer to view it

    • answer.zip