Function to calculate the sum of all elements of a binary tree


static int sumOfAllBinaryTreeElements(treeNode *rootNode) {

	if (rootNode == NULL)
		return 0;
	else
		return sumOfAllBinaryTreeElements(rootNode->leftChild) + rootNode->val
				+ sumOfAllBinaryTreeElements(rootNode->rightChild);

}

above mention function is member function of my Tree ADT class you can check complete program here

A Developer
Gy@n!

About Gyaneshwar Pardhi

Exploring the world and trying to know how can i involve to make this perfect. Gy@n!
This entry was posted in c++, Data Structure, interview Question, Programming and tagged , . Bookmark the permalink.

Leave a comment