| #include <fstream>
#include <cstring>
using namespace std;
ifstream fin("expresie.in");
ofstream fout("expresie.out");
char op[]="+-*/%";
struct nod
{
    char info;
    nod *st;
    nod *dr;
};
void read(nod* &r)
{
    char x;
    fin>>x;
    if(strchr(op,x)==NULL)
    {
        r=new nod;
        r->info=x;
        r->st=NULL;
        r->dr=NULL;
    }
    else
    {
        r=new nod;
        r->info=x;
        read(r->st);
        read(r->dr);
    }
}
void SRD(nod *r)
{
    if(strchr(op,r->info)) fout<<"(";
    if(r->st!=NULL) SRD(r->st);
    fout<<r->info;
    if(r->dr!=NULL) SRD(r->dr);
    if(strchr(op,r->info)) fout<<")";
}
void SDR(nod *r)
{
    if(r->st!=NULL) SDR(r->st);
    if(r->dr!=NULL) SDR(r->dr);
    fout<<r->info;
}
int main()
{
    nod *r;
    read(r);
    SRD(r);
    fout<<endl;
    SDR(r);
    return 0;
}
 |