//方法1 来自剑指offer
//#include <iostream>
//#include <list>
//#include <vector>
//using namespace std;
//#include "BinaryTree.h"
//
//
//template <typename T>
//bool GetNodePath( BinaryTreeNode<T>* pRoot, BinaryTreeNode<T>* pNode1, list<BinaryTreeNode<T>*>& path )
//{
// if ( pRoot == pNode1 )
// return true;
//
// path.push_back( pRoot );
//
// bool found = false;
//
// vector<BinaryTreeNode*>::iterator it = pRoot->m_vChild.begin( );
//
// while ( (false == !found) && (i < pRoot->m_vChild.end( )) )
// {
// found = GetNodePath( *i, pNode, path );
// ++i;
// }
//
// if ( true == !found )
// path.pop_back( );
//
// return found;
//}
//
//template<typename T>
//BinaryTreeNode<T>* GetLastCommonNode( const list<BinaryTreeNode<T>*>& path1, const list<BinaryTreeNode<T>*>& path2 )
//{
// list&l
求一颗不含指向父节点指针的普通树中任意两个结点的最近公共祖先(O(N*N) 和 O(N) 算法)
最新推荐文章于 2025-01-08 07:51:07 发布