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. oracle 序列重置

    问题一:怎样重置oracle序列 oracle序列创建以后,假设想重置序列从 0 開始,逐渐递增1,能够採用例如以下存储过程: create or replace procedure reset_se ...

  2. [腾讯 TMQ] 零基础学习 Fiddler 抓包改包

    本文转载于https://testerhome.com/topics/7159 一.Fiddler1.1.简介Fiddler是一款HTTP协议调试代理工具,它能够抓取记录本机所有HTTP(S)请求,通 ...

  3. Unable to connect to a repository at URL 解决方法

    提示"Unable to connect to a repository at URL 'svn://localhost/project1/'" or “Can't connect ...

  4. HTMLTestRunner 异常输出中文乱码

    1.在代码中加入下面的代码并保存: # -.- coding:utf-8 -.- import sys reload(sys) sys.setdefaultencoding('utf-8') 2.找到 ...

  5. GitHub for window 使用教程

    Git是目前最先进的分布式版本控制系统,作为一个程序员,我们需要掌握其用法. 一:下载GitHub for Windows   二:安装GitHub  下载之后点击进行安装过程,安装之后桌面上会有两个 ...

  6. 一个方便的图片载入框架——ImageViewEx

    我的博客:http://mrfufufu.github.io/ 一.前言 近期在整理项目中的一些代码,以备即将开展的新项目中使用,刚刚整理到一个图片载入的 lib.用起来很的简单,和 picasso ...

  7. 定时器:Timer:System.Threading.Timer类(转)

    最近的一个项目有一些地方需要用到定时功能,在设计过程中,突然发现.net的Timer类居然还有很多我以前没有用过的功能,这里就跟大家分享一下 注:这里的Timer类特指System.Threading ...

  8. Jlink升级_官网

    Jlink官网:https://www.segger.com/ 关于JLINK固件丢失或升级固件后提示Clone的解决办法 本人用的JLINK仿真器(某宝上买的),在使用新版KEIL时,提示要升级固件 ...

  9. 最小生成树——Kruskal(克鲁斯卡尔)算法

    [0]README 0.1) 本文总结于 数据结构与算法分析, 源代码均为原创, 旨在 理解 Kruskal(克鲁斯卡尔)算法 的idea 并用 源代码加以实现: 0.2)最小生成树的基础知识,参见 ...

  10. Eclipse搭建C++开发环境

    http://jingyan.baidu.com/article/456c463b67b4310a59314468.html