#include #include #include typedef struct dugum{ int deger; dugum *sol; dugum *sag; }; dugum * ekle (dugum * kok , int eklenen){ if(kok == NULL){ kok = (dugum *) malloc(sizeof(dugum)); kok ->deger = eklenen; kok->sol =NULL; kok->sag =NULL; return kok; } else if (eklenen < kok ->deger){ kok->sol = ekle(kok->sol , eklenen); } else if (eklenen > kok->deger ) { kok->sag = ekle(kok->sag , eklenen); } else{ // aynı değer ikinci kere bulundu } return kok; } void bastir(dugum *kok, int bosluk){ for(int i = 0;i< bosluk ; i++) printf("\t"); printf("%d",kok->deger); if(kok->sol!= NULL){ printf("\n+"); bastir(kok->sol, bosluk); } if(kok->sag!= NULL) { bastir(kok->sag,++bosluk); printf("\n"); } } int main(){ dugum *kok =NULL; /*= (dugum * ) malloc(sizeof(dugum)); kok->deger = 10; kok->sol = (dugum *) malloc(sizeof(dugum)); kok->sol->deger = 5; kok->sag = (dugum *) malloc (sizeof(dugum)); kok->sag->deger = 15;*/ kok = ekle(kok,3); kok = ekle(kok,7); kok = ekle(kok,5); kok = ekle(kok,6); kok = ekle(kok,11); kok = ekle(kok,17); kok = ekle(kok,12); getch(); bastir(kok,0); getch(); return 0; }