输入一个整数和一棵二元树,打印出所有和为该整数的二元树中的路径
2016-07-07 16:29
337 查看
从根节点到叶子节点经过的所有节点为一个路径.
//path 用于保存路径
void findPath(BinaryTreeNode * root, int target, int n, int path[])
{
if(!root)
return ;
target -= root->m_nValues;
path[n++] = root->m_nValues;
if(target == 0)
{
showPath(path, n);
}
findPath(root->m_pLeft, target, n, path);
findPath(root->m_pRight, target, n, path);
}
//path 用于保存路径
void findPath(BinaryTreeNode * root, int target, int n, int path[])
{
if(!root)
return ;
target -= root->m_nValues;
path[n++] = root->m_nValues;
if(target == 0)
{
showPath(path, n);
}
findPath(root->m_pLeft, target, n, path);
findPath(root->m_pRight, target, n, path);
}
相关文章推荐
- DWR3实现服务器端向客户端精确推送消息
- 报道一日记
- 无线通讯LoRa---SX1278芯片开发笔记
- maven报错非法字符:\65279 错误
- 走着走着就散了--徐志摩
- 美团在Redis上踩过的一些坑-目录(本人非美团)(转)
- JAVA JLabel自定义子类无法显示
- 在cmd模式下对mysql的操作语句
- javaScript 数组遍历方法总结
- oracle分析函数:二、秩运算(DENSE_RANK函数,RANK函数)
- 矩阵中的路径
- struts2--知识点
- Linux下学习DB2命令的笔记
- Android应用性能测试
- CSS自动换行,强迫不换行
- 1166 矩阵取数游戏[区间dp+高精度]
- struts声明式异常
- 进程退出前删除自身EXE
- RTSP协议、RTMP协议、HTTP协议的区别
- Hadoop应用开发,常见错误