CS2143-2144 Data Structures Quiz 9: Binary Tree Functions, Exercises of Data Structures and Algorithms

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

2011/2012

Uploaded on 07/11/2012

dharanidhar
dharanidhar 🇮🇳

4.2

(6)

58 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS2143-2144 Data Structures Spring 2012
Quiz # 9 (8 May 2012)
Time 10 Minutes
Max. Marks 10
Name: Reg. No: ___
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);
};
Docsity.com

Partial preview of the text

Download CS2143-2144 Data Structures Quiz 9: Binary Tree Functions and more Exercises Data Structures and Algorithms in PDF only on Docsity!

CS2143-2144 Data Structures Spring 2012

Quiz # 9 (8 May 2012)

Time 10 Minutes

Max. Marks 10

Name: Reg. No: ___

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); };

Docsity.com