Question: Using the Stack and Queue developed by yourself in part(i) construct the following ADT of Binary Tree. Implement the BuildTree method. template class BinaryTree {
template
class BinaryTree
{
public:
//constructor
BinaryTree ();
//Build the binary tree from the data given in the array.
//If a node doesn't exist the array element is 0
void BuildTree(DT *Arr, int Size);
// post order traversal (iterative)
void PostOrderItr();
// level order traversal (iterative)
void LevelOrder();
// this function returns true if the Binary tree is a Binary Search Tree and
// false otherwise. Please implement it iteratively.
bool isBST();
// this function returns the height of the binary tree.
//Please implement it recursively.
int Height();
//This function returns the number of nodes present at
// level (passed in as a parameter) of the binary tree.
// root is at level 1
int NodesAtLevel(int level);
private:
// you may add any other private members that might be needed by recursive functions
BNode
};
#endif
iii. [Mark 10] Design and construct a main function that demonstrates all the functions you developed in part(ii) above. Build binary trees carrying your roll number using any datatype you like.use roll.no 123456
Step by Step Solution
3.39 Rating (149 Votes )
There are 3 Steps involved in it
To implement the Binary Tree ADT with the specified methods well first need to define the BNode stru... View full answer
Get step-by-step solutions from verified subject matter experts
