[algogeeks] Re: Vertical Sum in a given Binary Tree

2012-03-20 Thread Don
// Assuming a vector container template class which allocates space as needed and allows negative index values vector result = {0}; void verticalSum(tree *root, int dist=0) { if (root) { result[dist] += root->val; verticalSum(tree->left, dist-1); verticalSum(tree->right, dist+1);

[algogeeks] Re: Vertical Sum in a given Binary Tree

2012-03-19 Thread vikas
verticalSum( node * &root, List * &sum) { if(root == null) return; sum->data += root->data; verticalSum(root->left, sum->left); verticalSum(root->right, sum->right); } 1 / \ 2 3 / \/ \ 4 5 6 7 a b c d e Vsum(1, c) c= 1 V

[algogeeks] Re: vertical sum

2011-08-25 Thread vikas
use this verticalSum(node *root, List *l) { if(root == null) return; root->n += l->n; // check for l->left, l->right and if null, allocate and link them verticalSum(root->left, l->left); verticalSum(root->right, l->right); } On Aug 25, 8:20 pm, Anup Ghatage wrote: > If I'm not

[algogeeks] Re: vertical sum

2011-08-25 Thread WgpShashank
Hi Nikhil, have a Look & let me know if anything missed or any better way to make it efficient ? http://shashank7s.blogspot.com/2011/02/wap-to-findout-vrtical-sum-of-nodes.html Thanks Shashank Mani Computer Science Birla Institute of Technology Mesra -- You received this message because you