文件名称:Q4.8
-
所属分类:
- 标签属性:
- 上传时间:2014-11-20
-
文件大小:17.86kb
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
// 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/
Q4.8/.DS_Store
__MACOSX/
__MACOSX/Q4.8/
__MACOSX/Q4.8/._.DS_Store
Q4.8/Q4.8/
Q4.8/Q4.8/.DS_Store
__MACOSX/Q4.8/Q4.8/
__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/
Q4.8/Q4.8.xcodeproj/project.pbxproj
Q4.8/Q4.8.xcodeproj/project.xcworkspace/
Q4.8/Q4.8.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Q4.8/Q4.8.xcodeproj/project.xcworkspace/xcuserdata/
Q4.8/Q4.8.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/
Q4.8/Q4.8.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate
Q4.8/Q4.8.xcodeproj/xcuserdata/
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/Q4.8.xcscheme
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist
Q4.8/.DS_Store
__MACOSX/
__MACOSX/Q4.8/
__MACOSX/Q4.8/._.DS_Store
Q4.8/Q4.8/
Q4.8/Q4.8/.DS_Store
__MACOSX/Q4.8/Q4.8/
__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/
Q4.8/Q4.8.xcodeproj/project.pbxproj
Q4.8/Q4.8.xcodeproj/project.xcworkspace/
Q4.8/Q4.8.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Q4.8/Q4.8.xcodeproj/project.xcworkspace/xcuserdata/
Q4.8/Q4.8.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/
Q4.8/Q4.8.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate
Q4.8/Q4.8.xcodeproj/xcuserdata/
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/Q4.8.xcscheme
Q4.8/Q4.8.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.