Kod:
#include <stdio.h>
#include <stdlib.h>
typedef struct agac{
struct agac *sag, *sol;
int veri;
}agac;
agac* ekle(int veri, agac *klm){
if (!klm){
klm = (agac*)malloc(sizeof(agac));
klm->veri = veri;
klm->sag = NULL;
klm->sol = NULL;
return klm;
}
else{
if (veri>klm->veri){
klm->sag = ekle(veri, klm->sag);
}
else if (veri<klm->veri){
klm->sol = ekle(veri, klm->sol);
}
}
return klm;
}
agac* bul(agac *slm,int veri){
if (veri == slm->veri)return slm;
else if (veri == slm->sag->veri)return slm->sag;
else if (veri == slm->sol->veri)return slm->sol;
else return NULL;
bul(slm->sag, veri);
bul(slm->sol, veri);
}
**** bastir(agac *klm){
if (!klm)return;
printf("%d %p %p\n", klm->veri, klm->sag, klm->sol);
bastir(klm->sag);
bastir(klm->sol);
}
int main(){
agac *klm = NULL;
for (int i = 0; i <= 5; i++){
klm = ekle(i + 1, klm);
}
bastir(klm);
printf("\n\n");
printf("%d %p %p\n", bul(klm, 1)->veri, bul(klm, 1)->sol, bul(klm, 1)->sag);
getchar();
}