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 閱讀(303) 評論(0)  編輯  收藏 所屬分類: Others

          主站蜘蛛池模板: 乐安县| 永靖县| 旬邑县| 筠连县| 屯留县| 兴安县| 饶平县| 张掖市| 东莞市| 巫溪县| 中卫市| 康马县| 防城港市| 洞口县| 渝中区| 德州市| 新余市| 朔州市| 安塞县| 大新县| 临沂市| 大埔县| 江西省| 秦皇岛市| 彩票| 莎车县| 桦甸市| 平罗县| 呼和浩特市| 永和县| 襄樊市| 绥江县| 阿图什市| 吉首市| 绵竹市| 和平县| 枣阳市| 田东县| 黎川县| 克东县| 台中市|