2#include3#include4#include5#include6#include7#include8#include9usingnamespacestd;1011structn" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Data Structure Binary Tree: Boundary Travers

系統 1972 0

http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/

      
         1
      
       #include <iostream>


      
         2
      
       #include <vector>


      
         3
      
       #include <algorithm>


      
         4
      
       #include <queue>


      
         5
      
       #include <stack>


      
         6
      
       #include <
      
        string
      
      >


      
         7
      
       #include <fstream>


      
         8
      
       #include <map>


      
         9
      
      
        using
      
      
        namespace
      
      
         std;


      
      
        10
      
      
        11
      
      
        struct
      
      
         node {


      
      
        12
      
      
        int
      
      
         data;


      
      
        13
      
      
        struct
      
       node *left, *
      
        right;


      
      
        14
      
           node() : data(
      
        0
      
      
        ), left(NULL), right(NULL) { }


      
      
        15
      
           node(
      
        int
      
      
         d) : data(d), left(NULL), right(NULL) { }


      
      
        16
      
      
        };


      
      
        17
      
      
        18
      
      
        void
      
       printleft(node *
      
        root) {


      
      
        19
      
      
        if
      
       (!root) 
      
        return
      
      
        ;


      
      
        20
      
      
        if
      
       (root->
      
        left) {


      
      
        21
      
               cout << root->data << 
      
        "
      
      
        "
      
      
        ;


      
      
        22
      
               printleft(root->
      
        left);


      
      
        23
      
      
            }


      
      
        24
      
      
        else
      
      
        if
      
       (root->
      
        right) {


      
      
        25
      
               cout << root->data << 
      
        "
      
      
        "
      
      
        ;


      
      
        26
      
               printleft(root->
      
        right);


      
      
        27
      
      
            }


      
      
        28
      
      
        }


      
      
        29
      
      
        30
      
      
        void
      
       printleaf(node *
      
        root) {


      
      
        31
      
      
        if
      
       (!root) 
      
        return
      
      
        ;


      
      
        32
      
           printleaf(root->
      
        left);


      
      
        33
      
      
        if
      
       (!root->left && !root->right) cout << root->data << 
      
        "
      
      
        "
      
      
        ;


      
      
        34
      
           printleaf(root->
      
        right);


      
      
        35
      
      
        }


      
      
        36
      
      
        37
      
      
        void
      
       printright(node *
      
        root) {


      
      
        38
      
      
        if
      
       (!root) 
      
        return
      
      
        ;


      
      
        39
      
      
        if
      
       (root->
      
        right) {


      
      
        40
      
               printright(root->
      
        right);


      
      
        41
      
               cout << root->data << 
      
        "
      
      
        "
      
      
        ;


      
      
        42
      
      
            }


      
      
        43
      
      
        else
      
      
        if
      
       (root->
      
        left) {


      
      
        44
      
               printright(root->
      
        left);


      
      
        45
      
               cout << root->data << 
      
        "
      
      
        "
      
      
        ;


      
      
        46
      
      
            }


      
      
        47
      
      
        }


      
      
        48
      
      
        49
      
      
        void
      
       printboundary(node *
      
        root) {


      
      
        50
      
      
        if
      
       (!root) 
      
        return
      
      
        ;


      
      
        51
      
           cout << root->data << 
      
        "
      
      
        "
      
      
        ;


      
      
        52
      
           printleft(root->
      
        left);


      
      
        53
      
      
            printleaf(root);


      
      
        54
      
           printright(root->
      
        right);


      
      
        55
      
      
        }


      
      
        56
      
      
        57
      
      
        int
      
      
         main() {


      
      
        58
      
           node *root = 
      
        new
      
       node(
      
        20
      
      
        );


      
      
        59
      
           root->left = 
      
        new
      
       node(
      
        8
      
      
        );


      
      
        60
      
           root->right = 
      
        new
      
       node(
      
        22
      
      
        );


      
      
        61
      
           root->left->left = 
      
        new
      
       node(
      
        4
      
      
        );


      
      
        62
      
           root->left->right = 
      
        new
      
       node(
      
        12
      
      
        );


      
      
        63
      
           root->right->right = 
      
        new
      
       node(
      
        25
      
      
        );


      
      
        64
      
           root->left->right->left = 
      
        new
      
       node(
      
        10
      
      
        );


      
      
        65
      
           root->left->right->right = 
      
        new
      
       node(
      
        14
      
      
        );


      
      
        66
      
      
            printboundary(root);


      
      
        67
      
      
        return
      
      
        0
      
      
        ;


      
      
        68
      
       }
    

?

Data Structure Binary Tree: Boundary Traversal of binary tree


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日韩国产精品视频 | 亚洲最大综合网 | 成人国产激情福利久久精品 | 美国毛片免费观看 | 免费一级特黄欧美大片久久网 | 日日操操干干 | sihu国产精品永久免费 | 久久久久亚洲精品一区二区三区 | 久久久久久久久网站 | 色九九亚洲偷偷动态图 | 欧美人猛交日本人xxx | 欧美一级亚洲一级 | 全部无卡免费的毛片在线看 | 久久综合久久综合久久 | 97影院九七影院理论片 | 毛片在线不卡 | 中文毛片 | 亚洲视频aaa | 波多野一区二区三区在线 | 日韩欧美精品一区二区 | 日韩欧美视频一区二区三区 | 久久在线影院 | 国产中文字幕在线免费观看 | 成人a毛片高清视频 | 最新狠狠色狠狠色综合 | 午夜视频福利 | 精品国产综合区久久久久久 | 噜噜啪 | 国产在线成人a | 久久高清免费 | 二级毛片 | 国产一区二区三区四区 | 玖玖在线 | 欧美视频在线视频 | 日韩视频在线观看一区二区 | 综合亚洲精品一区二区三区 | 婷婷综合在线 | 视频在线色 | www.中文字幕.com | 亚洲一区中文字幕 | 中文精品久久久久国产网址 |