Data Structure Binary Tree: Convert a given tree to its Sum Tree
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的更多相关文章
- 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 ...
- 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 ...
- 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 < ...
- 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 ...
- 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 ...
- Data Structure Binary Tree: Iterative Postorder Traversal
http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...
- Data Structure Binary Tree: Largest Independent Set Problem
http://www.geeksforgeeks.org/largest-independent-set-problem/ #include <iostream> #include < ...
- Data Structure Binary Tree: Morris traversal for Preorder
http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...
- 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 ...
随机推荐
- 自己定义View时,用到Paint Canvas的一些温故,讲讲平时一些效果是怎么画的(基础篇 一)
转载请注明出处王亟亟的大牛之路 之前也有一个相似于画板的操作,可是不够具体,这边先补上链接.有兴趣的小伙伴能够看看http://blog.csdn.net/ddwhan0123/article/det ...
- IBM Security AppScan Glass Box:一种全新的漏洞扫描思想
IBM Security AppScan Glass Box:一种全新的漏洞扫描思想 Glass Box 是 IBM Security AppScan Standard Edition(以下简称 Ap ...
- 修改NameNode端口后,hive表查询报错
在进行使用hive查询表数据的时候,抛出异常 hive> select*from blackList;FAILED: SemanticException Unable to determine ...
- entity framework core 调用存储过程和方法
目前EF Core调用存储过程,限制很多,比如返回结果必须是定义好的DbSet<>等等.这里用一种曲线救国的方式,自定义两个方法,用原始ado.net解决问题.以MySql数据库为例,代码 ...
- Cocoa 静态显示一个对话框
M // // form2.m // test_multi_window // // Created by on 23/7/14. // Copyright (c) 2014 EDU. All rig ...
- Docker-Compose 自动创建的网桥与局域网冲突解决方案
环境: 使用docker-compose.yml 部署应用,docker 默认的网络模式是bridge ,默认网段是172.17.0.1/16 ,不巧的是我们局域网也使用的172.22. xx 网段 ...
- 在Ubuntu下利用Eclipse开发FFmpeg配置小结
首先需要编译FFmpeg得到头文件和lib文件,参见:在Ubuntu下编译FFmpeg 选择File-New-C Project 选择Executable下的Empty Project,右侧选择Lin ...
- CSS3 - 鼠标移入移出时改变样式
1,使用伪类实现样式切换伪类是CSS2.1时出现的新特性,让许多原本需要JavaScript才能做出来的效果使用CSS就能实现.比如实现下面的鼠标悬停效果,只要为:hover伪类应用一组新样式即可.当 ...
- 从零开始写一个Exporter
前言 上一篇文章中已经给大家整体的介绍了开源监控系统Prometheus,其中Exporter作为整个系统的Agent端,通过HTTP接口暴露需要监控的数据.那么如何将用户指标通过Exporter的形 ...
- GS与MS之间通信
GS与MS之间通信 注意GS与MS是两个线程,现在是每个map一个线程,他们之间是内部协议进行通信的,那既然是两个线程那如何通信呢,看了net进程通信这个就比较简单了 举个例子 m_pMap-> ...