You are on page 1of 2

#include<stdio.

h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
typedef struct nodl
{
char nume[20];
int numar,cant_lapte;
struct nodl *urm;
}sublista;
typedef struct noda
{
char strada[20];
struct noda *stang,*drept;
sublista *prim;
}arbore;
arbore *radacina=NULL;
sublista *adaugare_nod_sublista(sublista *l, char n[], int nr, int cant)
{
sublista *q1,*q2,*aux;
aux=(sublista*)malloc(sizeof(sublista));
strcpy(aux->nume,n);
aux->numar=nr;
aux->cant_lapte=cant;
for(q1=q2=l;q1!=NULL && strcmp(q1->nume,n)<0;q2=q1,q1=q1->urm);
if(q1!=NULL && strcmp(q1->nume,n)==0)
{
printf("Exista in lista");
return l;
}
else
if(q1!=q2)
{
q2->urm=aux;
aux->urm=q1;
return l;
}
else
{
aux->urm=l;
return aux;
}
}
arbore *adaugare_nod_arbore(arbore *t,char ns[],char n[],int nr,int cant)
{
if(t==NULL)
{
t=(arbore*)malloc(sizeof(arbore));
strcpy(t->strada,ns);
t->drept=NULL;
t->stang=NULL;
t->prim=NULL;
t->prim=adaugare_nod_sublista(t->prim,n,nr,cant);
}
else

if(strcmp(t->strada,ns)<0)
t->drept=adaugare_nod_arbore(t->drept,ns,n,nr,cant);
else
if(strcmp(t->strada,ns)>0)
t->stang=adaugare_nod_arbore(t->stang,ns,n,nr,ca
nt);
else
t->prim=adaugare_nod_sublista(t->prim,n,nr,cant)
;
return t;
}
void citire()
{
FILE *f;
char ns[20],n[20];
int nr,cant;
f=fopen("data.txt","rt");
while(!feof(f))
{
fscanf(f,"%s %s %d %d",&ns,&n,&nr,&cant);
radacina=adaugare_nod_arbore(radacina,ns,n,nr,cant);
}
}
sublista afisare(sublista *l)
{
sublista *q;
q=l;
while(q!=NULL)
{
printf("%s %d %d\n",q->nume,q->numar,q->cant_lapte);
q=q->urm;
}
}
arbore tiparire(arbore *t)
{
if(t!=NULL)
{
tiparire(t->stang);
printf("%s \n",t->strada);
afisare(t->prim);
tiparire(t->drept);
}
}
void main()
{
citire();
tiparire(radacina);
printf("\n");
printf("\n");
//cautare(radacina,"a25");
//tiparire_cant(radacina,50);
getch();
}