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

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Data Structure Binary Tree: Boundary Travers

系統 2268 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條評論
主站蜘蛛池模板: 德化县| 汤原县| 交口县| 巴塘县| 齐齐哈尔市| 双牌县| 鹤庆县| 阿拉善盟| 东港市| 武强县| 无极县| 三河市| 通辽市| 南开区| 西吉县| 永仁县| 台中市| 罗甸县| 南丰县| 迁安市| 文水县| 三门峡市| 多伦县| 济南市| 玛纳斯县| 浦县| 宜良县| 广安市| 五常市| 淄博市| 老河口市| 芒康县| 通州区| 吉木乃县| 错那县| 麻栗坡县| 天祝| 平顺县| 酒泉市| 夏河县| 九江县|