Cod sursa(job #1318002)

Utilizator valentin322Valentin L valentin322 Data 15 ianuarie 2015 14:48:12
Problema Arbore partial de cost minim Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ElementeLinieArbore.in");
int niv,k,c,maxi;
typedef struct un_nod
{ int info;
un_nod *st,*dr;
}TNOD;
TNOD *rad;

void creare(TNOD *&p)
    {
        int x;
        f>>x;
        if(x==0)p=NULL;
        else
        {
            p=new TNOD;
            p->info=x;
            p->st=NULL;
            p->dr=NULL;
            creare(p->st);
            creare(p->dr);
        }

    }
void RSD (TNOD *&p,int niv,int k)
{
    if(p!=NULL)
    {
        if (k==niv) {c++; if((p->info)>maxi) maxi=(p->info);}
        RSD(p->st,niv,k+1);
        RSD(p->dr,niv,k+1);
    }
}

int main()
{
    f>>niv;
    rad=new TNOD;
    creare(rad);
    maxi=-3200;
    RSD(rad,niv,1);
    cout<<c;
    cout<<endl;
    cout<<maxi;
    return 0;
}