Tag: code

Find the level with Maximum Sum in a Binary Tree

Algorithm: [sourcecode lang=”cpp”] int FindLevelWithMaxSum() { tree_node *temp; int level=0, maxLevel=0; std::queue<tree_node *> Q; int currentSum=0, maxSum=0; if(!root) return 0; Q.push(root); Q.push(NULL); while(!Q.empty()) { temp=Q.front(); Q.pop(); if(temp==NULL) { if(currentSum>maxSum) {… Read more »