zoukankan      html  css  js  c++  java
  • POJ 2255

    //由先中序建树,然后后序遍历 
    #include <cstring>
    #include <string>
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    typedef struct Node
    {
        char data;
        Node *lchild,*rchild;
    }Node,*Bitree;
    Bitree creat(string s1,string s2)
    {
        if(s1.length()==0)//到叶子节点 
            return NULL;
        Node *root = new Node;
        if(!root)
            exit(-1);
        root->data=s1[0];
        size_t pos = s2.find(s1[0]);
        root->lchild=creat(s1.substr(1,pos),s2.substr(0,pos));
        root->rchild=creat(s1.substr(pos+1),s2.substr(pos+1));
        return root;
    }   
    void postorder(Node *root)
    {
        if(root)
        {
            postorder(root->lchild);
            postorder(root->rchild);
            cout<<root->data;
        }
    }
    int main()
    {
        string s1,s2;
        while(cin>>s1>>s2)
        {
            Node *root;
            root=creat(s1,s2);
            postorder(root);
            putchar('\n');
           // system("pause");
        }
        return 0;
    }
            
            
    
  • 相关阅读:
    混合背包
    二维背包
    0/1背包问题(DP)
    冒泡排序
    快速排序
    最长上升子序列
    二分查找
    n后问题
    crontab 定时任务
    删除以某字符串开头的表
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2626546.html
Copyright © 2011-2022 走看看