Orar semigroup #2

Orar semigroup #2

5/11 - Arbori binari


#include<iostream>
#include<fstream>
using namespace std;
ifstream f("date");
struct nod{int info;
nod* st,*dr;};

nod* creare()
{int x;
f>>x;
if(x)
{nod*p=new nod;
p->info=x;
p->st=creare();
p->dr=creare();
return p;}
else return NULL;}

void RSD(nod* R)
{if(R)
{cout<<R->info;
RSD(R->st);
RSD(R->dr);}

}

void fii(nod* R, int x)
{if(R)
{if(x==R->info)
{if(R->st)
    cout<<R->st->info<<" ";
if(R->dr)
    cout<<R->dr->info<<" ";
}
fii(R->st,x);
fii(R->dr,x);
}
}

int suma(nod* R)
{
    if(R)
        return R->info+suma(R->st)+suma(R->dr);
    else return 0;
}

int main()
{nod* R;
R=creare();
RSD(R);
cout<<endl;
fii(R,3);
cout<<endl;
cout<<suma(R);
}

duminică, 10 iunie 2012 by DlMuresan
Categories: | 1 comment

One Comment

  1. http://i48.tinypic.com/2h5o0f8.png

Leave a Reply