• <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 閱讀(225) 評論(0)  編輯 收藏 引用 所屬分類: Data structure and algorithms

            亚洲精品无码久久千人斩| 亚洲国产精品久久久天堂| 日韩亚洲欧美久久久www综合网| 青青青国产精品国产精品久久久久 | 伊人久久大香线蕉av不卡| 国产情侣久久久久aⅴ免费| 国产成人99久久亚洲综合精品| 香蕉aa三级久久毛片| 国产99久久精品一区二区| 亚洲精品国产自在久久| 天天久久狠狠色综合| 亚洲色欲久久久综合网| 午夜精品久久影院蜜桃| 久久亚洲国产午夜精品理论片| 久久人人爽人人爽人人爽| 秋霞久久国产精品电影院| 亚洲∧v久久久无码精品| 日韩十八禁一区二区久久| 国产AⅤ精品一区二区三区久久| 久久国产精品一国产精品金尊| 亚洲а∨天堂久久精品| 国产激情久久久久影院小草 | 久久久久精品国产亚洲AV无码 | 久久91精品久久91综合| 精品久久久久久中文字幕大豆网| 久久无码AV中文出轨人妻| 99热热久久这里只有精品68| 久久久免费精品re6| 日韩人妻无码精品久久久不卡| 三级韩国一区久久二区综合| 久久久精品久久久久特色影视| 久久精品国产亚洲av瑜伽| 国产精品VIDEOSSEX久久发布| 久久99免费视频| 国产成人精品久久免费动漫| 7777久久亚洲中文字幕| 精品久久无码中文字幕| 久久99精品综合国产首页| 色综合久久综精品| 色婷婷久久综合中文久久一本| 久久久WWW成人免费毛片|