ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 1991번 C++ 풀이
    백준 2018. 10. 7. 23:17
    #include <iostream>
    #include <algorithm>
    #include <queue>
    using namespace std;
    struct node {
    int value;
    node * left;
    node * right;
    };
    struct node tree[28];

    void preFix(node a){
    cout << (char) (a.value+'A');
    if (a.left != NULL){
    preFix(*a.left);
    }
    if (a.right != NULL){
    preFix(*a.right);
    }
    }
    void inOrder(node a){
    if (a.left != NULL){
    inOrder(*a.left);
    }
    cout << (char) (a.value+'A');

    if (a.right != NULL){
    inOrder(*a.right);
    }
    }
    void postFix(node a){
    if (a.left != NULL){
    postFix(*a.left);
    }
    if (a.right != NULL){
    postFix(*a.right);
    }

    cout << (char) (a.value+'A');

    }

    int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (auto i=0; i<n; i++){
    tree[i].value = i;
    }
    for (auto i=0; i<n; i++){
    char value, left, right;
    cin >> value >> left >> right;
    // cout << value- 'A';
    if (left != '.'){
    tree[value- 'A'].left = &tree[ (left-'A')];
    }
    if (right != '.'){
    tree[value- 'A'].right = &tree[ (right-'A')];
    }
    }
    preFix(tree[0]);
    cout << '\n';
    inOrder(tree[0]);
    cout << '\n';
    postFix(tree[0]);

    }


    '백준' 카테고리의 다른 글

    백준 C++ 2161번 풀이  (0) 2018.11.16
    백준 11725번 C++ 풀이  (0) 2018.10.09
    백준 1300번 C++ 풀이  (0) 2018.10.07
    백준 10815번 C++ 풀이  (0) 2018.10.07
    백준 1890 C++ 풀이  (0) 2018.10.04
Designed by Tistory.