• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Zero Lee的專欄

            Convert one binary search tree to double-linked list

            Give one binary search tree, and convert it to one double-linked list
            Cpp code demo as below:
             1 struct BSTreeNode
             2 {
             3     int m_value;
             4     BSTreeNode* m_pLeft;
             5     BSTreeNode* m_pRight;
             6 };
             7 
             8 BSTreeNode* convert(BSTreeNode* phead, bool asRight)
             9 {
            10     if (!phead)
            11         return NULL;
            12     BSTreeNode* pLeft = 0*pRight=0;
            13     if (phead->m_pLeft)
            14         pLeft = convert(phead->m_pLeft, false);
            15     if (pLeft) {
            16         pLeft->m_pRight = phead;
            17         phead->m_pLeft = pLeft;
            18     }
            19     if (phead->m_pRight)
            20         pRight = convert(phead->m_pRight, true);
            21     if (pRight) {
            22         pRight->m_pLeft = phead;
            23         phead->m_pRight = pRight;
            24     }
            25     BSTreeNode* ptmp = phead;
            26     if (asRight) {
            27         while (ptmp->m_pLeft) {
            28             ptmp = ptmp->m_pLeft;
            29         }
            30     } else {
            31         while (ptmp->m_pRight) {
            32             ptmp = ptmp->m_pRight;
            33         }
            34     }
            35     return ptmp;
            36 }
            37 
            38 BSTreeNode* convert2doublelist(BSTreeNode* phead)
            39 {
            40     return convert(phead, true);
            41 }
            42 


            posted on 2010-10-18 12:30 Zero Lee 閱讀(218) 評論(0)  編輯 收藏 引用 所屬分類: Data structure and algorithms

            精品久久8x国产免费观看| 精品久久久无码中文字幕| 无码伊人66久久大杳蕉网站谷歌| 久久国产劲爆AV内射—百度| 精品久久久久久中文字幕人妻最新| 99久久精品国产一区二区| 香蕉久久影院| 久久综合九色综合欧美狠狠| 久久99精品国产麻豆宅宅| 欧美精品一区二区精品久久| 伊人伊成久久人综合网777| 97久久香蕉国产线看观看| 欧美性猛交xxxx免费看久久久| 成人综合伊人五月婷久久| 久久国产成人午夜aⅴ影院 | 久久久久国产精品| 日韩精品久久久久久久电影| 国产精品久久久久影院嫩草| 久久国产劲爆AV内射—百度| 久久se精品一区二区影院| 久久精品成人国产午夜| 久久精品国产99国产精品导航 | 国产精品久久久久国产A级| 亚洲欧美日韩精品久久亚洲区| 久久综合九色综合精品| 99久久精品国产高清一区二区 | 久久精品成人| 日本免费久久久久久久网站| 成人国内精品久久久久一区| 久久精品国产99久久久古代 | 亚洲国产天堂久久综合| 国产AV影片久久久久久| av午夜福利一片免费看久久| MM131亚洲国产美女久久| 久久国产精品无码一区二区三区| 久久亚洲精品无码VA大香大香| 亚洲精品第一综合99久久| 欧洲性大片xxxxx久久久| 亚洲国产成人久久综合碰| 国产精品美女久久久久av爽| 久久久精品久久久久久|