ITPub博客

首页 > 应用开发 > > 怎么将这段代码改写成C++版本的

怎么将这段代码改写成C++版本的

作者:doudourabbit 时间:2019-08-20 11:26:30 0 删除 编辑

#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <queue>

using namespace std;

#define inf 0x3f3f3f3f

typedef struct node

{

char x;

struct node *lc,*rc;

}node,*tree;

char pre[100],in[100],post[100];

void topost(char pre[],char in[],char post[],int l)

{

int i;

if(l<=0) return ;

for(i=0;i<l;i++)

if(in[i]==pre[0]) break;

post[l-1]=pre[0];

topost(pre+1,in,post,i);

topost(pre+i+1,in+i+1,post+i,l-1-i);

}

int main ()

{

int i,j,l;

while(gets(pre))

{

gets(in);

l=strlen(pre);

topost(pre,in,post,l);

for(i=0;i<l;i++)

printf("%c",post[i]);

printf("\n");

}

return 0;

}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4809/viewspace-3157406/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-25

  • 博文量
    193
  • 访问量
    1438