weidagang2046的專欄

          物格而后知致
          隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
          數據加載中……

          Find Common Ancestor

          Find Common Ancestor
          Problem: find the common ancestor of two nodes in a tree

          Given a "tree" pointer pointing to the root node of a tree and the other two pointers to two nodes in the tree. You are expected to write a C++ subroutine to find the common ancestor of the two nodes. In any unexpected condition, your code should return null pointer and avoid crashing.

          For example, if the tree is like below, B is the common ancestor of E and G; A is the common ancestor of H and F; D is the common ancestor of D and G.

           
          gailya 20:30:17
          You are allowed to use recursion but as few as possible. You are NOT allowed to use STL. Please follow the type definitions shown below:

          //tree node type
          typedef struct _Node
          ...{
              char value;
              struct _Node* left;
              struct _Node* right;
          }Node;

          class CommonNodeFinder
          ...{
              //add any auxiliary code here as you wish.
          public:
              inline Node* FindCommonAncestor(Node* tree, Node* node_1, Node* node_2)
              ...{
                  //your code here.
              }
          }

          posted on 2005-10-27 21:06 weidagang2046 閱讀(301) 評論(0)  編輯  收藏 所屬分類: Others

          主站蜘蛛池模板: 丹巴县| 衡山县| 大连市| 新乡市| 禄丰县| 甘洛县| 乡宁县| 河曲县| 来宾市| 淳安县| 额尔古纳市| 西林县| 咸阳市| 广水市| 遵化市| 靖州| 吴忠市| 门源| 灵寿县| 陆良县| 噶尔县| 荆州市| 阳谷县| 农安县| 体育| 那曲县| 惠东县| 闵行区| 吉木萨尔县| 汉阴县| 库伦旗| 万源市| 绥化市| 南充市| 新巴尔虎左旗| 马公市| 饶河县| 凌云县| 元谋县| 娱乐| 内丘县|