赞
踩
#include<bits/stdc++.h> using namespace std; typedef struct BiTnode{ char data; struct BiTnode *left,*right; }BiTnode,*BiTree; void CreatTree(BiTree &t,char s[],int &i){ if(s[i] == '0'){ t = NULL; }else{ t = new BiTnode; t->data = s[i]; CreatTree(t->left,s,++i); CreatTree(t->right,s,++i); } } void ChangeLeftAndRight(BiTree &t){ if(t){ BiTree tt; tt = t->left; t->left = t->right; t->right = tt; ChangeLeftAndRight(t->left); ChangeLeftAndRight(t->right); } } void PreOrder(BiTree &t){ if(t){ cout<<t->data; PreOrder(t->left); PreOrder(t->right); } } int main(){ while(1){ char s[100]; int i = 0; cin>>s; if(s[0] == '0'){ break; } BiTree t; CreatTree(t,s,i); ChangeLeftAndRight(t); PreOrder(t); cout<<endl; } return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。