首页 > 代码库 > 二叉树和为某值

二叉树和为某值

很容易想到用先序遍历,并传递进去一个数组和当前和。just so so

代码:

#include <iostream>
#include <vector>
#include <assert.h>

using namespace std;

typedef struct tree{
	int data;
	struct tree * lchild;
	struct tree * rchild;
}Tree,*pTree;

void  createTree(pTree  &pHead){
	int temp;
	scanf("%d",&temp);
	if(temp){
		pHead  = new Tree();
		pHead->data = http://www.mamicode.com/temp;>
运行结果: