文件名称:Q4.8
介绍说明--下载内容均来自于网络,请自行研究使用
// You are given a binary tree in which each node contains a value. Design a lgorithm to print all paths which sum up to that value. Note that it can be any path in the tree - it does not have to start at the root.
// 给定一棵二叉树,每个结点包含一个值。打印出所有满足以下条件的路径: 路径上结点的值加起来等于给定的一个值。注意:这些路径不必从根结点开始。
方案1:如果结点中包含指向父亲结点的指针,那么,只需要去遍历这棵二叉树, 然后从每个结点开始,不断地去累加上它父亲结点的值直到父亲结点为空(这个具有唯一性, 因为每个结点都只有一个父亲结点。也正因为这个唯一性, 可以不另外开额外的空间来保存路径),如果等于给定的值sum,则打印输出。
方案2:如果结点中不包含指向父亲结点的指针,则在二叉树从上向下查找路径的过程中, 需要为每一次的路径保存中间结果,累加求和仍然是从下至上的,对应到保存路径的数组, 即是从数组的后面开始累加的,这样能保证遍历到每一条路径。
-// You are given a binary tree in which each node contains a value Design an algorithm to print all paths which sum up to that value Note that it can be any path in the tree-.. It does not have to start at the root // Given a binary tree, each node contains a value. Print out all the following conditions are met path: the path to the node values add up to a given value. Note: These paths do not have to start the root. Scenario 1: If the node contains a pointer pointing to the father node, then just go to traverse the binary tree, and then start each node to constantly tired, plus the value of its parent node until the father node empty (this is unique, because each node has only one parent node. It is because of this uniqueness, can not otherwise open additional space to store the path), if the value is equal to a given sum, the printout . Scenario 2: If the node does not contain a pointer pointing to the father node, then the binary search path down the process, t
// 给定一棵二叉树,每个结点包含一个值。打印出所有满足以下条件的路径: 路径上结点的值加起来等于给定的一个值。注意:这些路径不必从根结点开始。
方案1:如果结点中包含指向父亲结点的指针,那么,只需要去遍历这棵二叉树, 然后从每个结点开始,不断地去累加上它父亲结点的值直到父亲结点为空(这个具有唯一性, 因为每个结点都只有一个父亲结点。也正因为这个唯一性, 可以不另外开额外的空间来保存路径),如果等于给定的值sum,则打印输出。
方案2:如果结点中不包含指向父亲结点的指针,则在二叉树从上向下查找路径的过程中, 需要为每一次的路径保存中间结果,累加求和仍然是从下至上的,对应到保存路径的数组, 即是从数组的后面开始累加的,这样能保证遍历到每一条路径。
-// You are given a binary tree in which each node contains a value Design an algorithm to print all paths which sum up to that value Note that it can be any path in the tree-.. It does not have to start at the root // Given a binary tree, each node contains a value. Print out all the following conditions are met path: the path to the node values add up to a given value. Note: These paths do not have to start the root. Scenario 1: If the node contains a pointer pointing to the father node, then just go to traverse the binary tree, and then start each node to constantly tired, plus the value of its parent node until the father node empty (this is unique, because each node has only one parent node. It is because of this uniqueness, can not otherwise open additional space to store the path), if the value is equal to a given sum, the printout . Scenario 2: If the node does not contain a pointer pointing to the father node, then the binary search path down the process, t
(系统自动生成,下载前可以参看下载内容)
下载文件列表
Q4.8
....\.DS_Store
__MACOSX
........\Q4.8
........\....\._.DS_Store
Q4.8\Q4.8
....\....\.DS_Store
__MACOSX\Q4.8\Q4.8
........\....\....\._.DS_Store
Q4.8\Q4.8\main.cpp
__MACOSX\Q4.8\Q4.8\._main.cpp
Q4.8\Q4.8\Q4_8.1
__MACOSX\Q4.8\Q4.8\._Q4_8.1
Q4.8\Q4.8.xcodeproj
....\..............\project.pbxproj
....\..............\project.xcworkspace
....\..............\...................\contents.xcworkspacedata
....\..............\...................\xcuserdata
....\..............\...................\..........\mac.xcuserdatad
....\..............\...................\..........\...............\UserInterfaceState.xcuserstate
....\..............\xcuserdata
....\..............\..........\mac.xcuserdatad
....\..............\..........\...............\xcschemes
....\..............\..........\...............\.........\Q4.8.xcscheme
....\..............\..........\...............\.........\xcschememanagement.plist