zoukankan      html  css  js  c++  java
  • poj1577

    排序二叉树

    View Code
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    #define maxn 105
    
    struct Node
    {
        Node *left, *right;
        char letter;
    }tree[maxn];
    
    char st[maxn];
    int node_cnt;
    
    void insert(Node * &proot, char ch)
    {
        if (proot == NULL)
        {
            proot = &tree[node_cnt++];
            proot->left = NULL;
            proot->right = NULL;
            proot->letter = ch;
            return;
        }
        if (ch > proot->letter)
            insert(proot->right, ch);
        else
            insert(proot->left, ch);
    
    }
    
    void output(Node *proot)
    {
        putchar(proot->letter);
        if (proot->left)
            output(proot->left);
        if (proot->right)
            output(proot->right);
    }
    
    void input()
    {
        char *p = st;
        while (1)
        {
            scanf("%s", p);
            if (*p == '*')
                return;
            if (*p == '$')
                return;
            p = st + strlen(st);    
        }
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        while (1)
        {
            input();
            Node *proot = NULL;
            node_cnt = 0;
            for (int i = strlen(st) - 2; i >= 0; i--)
                insert(proot, st[i]);
            output(proot);
            putchar('\n');
            if (st[strlen(st) - 1] == '$')
                break;
        }
        return 0;
    }
  • 相关阅读:
    9.4
    9.3
    9.2
    2016.9.1
    html,body
    prototype
    京东笔试题的一些小细节
    gulp安装过程中的问题。
    json
    双飞翼布局和圣杯布局
  • 原文地址:https://www.cnblogs.com/rainydays/p/2982709.html
Copyright © 2011-2022 走看看