
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 cs2143-2144 data structures quiz #9 from spring 2012. The quiz focuses on implementing functions for a binary tree class, including binarytreesum(), counttree(), leftsumtree(), and rightsumtree(). Students are required to write the code for these functions.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

For the following binary tree class, implement the following function:
int binaryTreeSum(node *t) // sum the values of all the nodes in the tree and return the sum int countTree(node *t) //count all the nodes of the binary tree and return the no of nodes int leftsumTree (node *t) // find sum of all the left children of the tree and return the value int rightsumTree(node *t) //find sum of all the right children of the tree and return the value
protected: struct node { node *lchild; int item; node *rchild; };
node *root; node *get_node();
public: bitree() { root = Null; } ~bitree() { destroy (root); } int Insert(int x, int p, char d); //to insert x as a left or right child of the node //whose content is p depending upon the value of d //(direction) as ‘L’ or ‘R’, respectively int binaryTreeSum(node *t); int countTree(node *t) ; int leftsumTree (node *t); int rightsumTree(node *t); };