http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
using namespace std; struct node {
int data;
struct node *left, *right;
node() : data(), left(NULL), right(NULL) { }
node(int d) : data(d), left(NULL), right(NULL) { }
}; void prints(node *root) {
if (!root) return;
prints(root->left);
cout << root->data << " ";
prints(root->right);
} int tosum(node *root) {
if (!root) return ;
int old = root->data;
root->data = tosum(root->left) + tosum(root->right);
return root->data + old;
} int main() {
node *root = new node();
root->left = new node(-);
root->right = new node();
root->left->left = new node();
root->left->right = new node(-);
root->right->left = new node();
root->right->right = new node();
tosum(root);
prints(root);
return ;
}

Data Structure Binary Tree: Convert a given tree to its Sum Tree的更多相关文章

  1. Data Structure Binary Tree: Convert a given Binary Tree to Doubly Linked List

    http://www.geeksforgeeks.org/in-place-convert-a-given-binary-tree-to-doubly-linked-list/ #include &l ...

  2. Data Structure Binary Tree: Convert an arbitrary Binary Tree to a tree that holds Children Sum Property

    http://www.geeksforgeeks.org/convert-an-arbitrary-binary-tree-to-a-tree-that-holds-children-sum-prop ...

  3. Data Structure Binary Search Tree: Find k-th smallest element in BST (Order Statistics in BST)

    http://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/ #include < ...

  4. Data Structure Binary Tree: Lowest Common Ancestor in a Binary Tree

    http://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/ #include <iostream> #in ...

  5. Data Structure Binary Tree: Print ancestors of a given binary tree node without recursion

    http://www.geeksforgeeks.org/print-ancestors-of-a-given-binary-tree-node-without-recursion/ #include ...

  6. Data Structure Binary Tree: Iterative Postorder Traversal

    http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...

  7. Data Structure Binary Tree: Largest Independent Set Problem

    http://www.geeksforgeeks.org/largest-independent-set-problem/ #include <iostream> #include < ...

  8. Data Structure Binary Tree: Morris traversal for Preorder

    http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...

  9. Data Structure Binary Tree: Construct Full Binary Tree from given preorder and postorder traversals

    http://www.geeksforgeeks.org/full-and-complete-binary-tree-from-given-preorder-and-postorder-travers ...

随机推荐

  1. Linux下利用phpize安装memcashe的php源码扩展包

    phpize是php的一种构建工具,为PHP扩展准备构建环境,通过phpize可以编译php的扩展源码文件为php扩展模块. 一.安装 phpize工具可以通过安装php-dev包自动集成安装.安装完 ...

  2. Write operations are not allowed in read-only mode (FlushMode.MANUAL)

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述 搭建SSH框架后,为测试事务配置是否生效,因此在事务配置中取消了保存方法,然后再保存方法中手动抛出异常(已测试配置事务后没有保存成功), ...

  3. 【已解决】iView-admin Editor 组件 绑定默认值问题

    iView-admin Editor 组件 绑定默认值问题 发现 editor 组件,设置v-model 后, 修改 v-model 数据, editor组件没有自动渲染,需要手动设置渲染  this ...

  4. 【Hadoop基础教程】1、Hadoop之服务器基础环境搭建(转)

    本blog以K-Master服务器基础环境配置为例分别演示用户配置.sudo权限配置.网路配置.关闭防火墙.安装JDK工具等.用户需参照以下步骤完成KVMSlave1~KVMSlave3服务器的基础环 ...

  5. eureka集群高可用配置,亲测成功配置(转)

    转自大神的文章:https://blog.csdn.net/tianyaleixiaowu/article/details/78184793 网上讲这个东西的很多,抄来抄去的,大部分类似,多数没讲明白 ...

  6. oracle高性能的SQL语句的写法

    1.当多表查询的时候,把数据量小的表放在最后面,ORACLE会把最后面的表当作基础表,因为表间连接时,最右边的表会被放到嵌套循环的最外层.最外层的循环次数越少,效率越高. 2.Oracle采用自下而上 ...

  7. dwr文件上传

    配置FileService映射: dwr.xml <create creator="new"> <param name="class" val ...

  8. android 学习mvc 和 mvp 和 mvvm参考项目

    githup地址:https://github.com/ivacf/archi 阿尔奇 此存储库展示并比较可用于构建Android应用程序的不同架构模式.完全相同的示例应用程序使用以下方法构建三次: ...

  9. 搜索maven的库中某个支持库的的最新版本

    首先放网址(建议挂个vpn): maven库中心:http://search.maven.org/ jcenter库中心:https://bintray.com/bintray/jcenter 接下来 ...

  10. poj1861 最小生成树 prim &amp; kruskal

    // poj1861 最小生成树 prim & kruskal // // 一个水题,为的仅仅是回味一下模板.日后好有个照顾不是 #include <cstdio> #includ ...