Created
October 28, 2018 22:02
SizzlingThisTest created by HasanAydin - https://repl.it/@HasanAydin/SizzlingThisTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// | |
// HASAN AYDIN | |
// 1306151344 | |
// www.onlinegdb.com sitesinden c++ turu ile denenmistir. | |
// | |
#include<stdlib.h> | |
#include<stdio.h> | |
struct Agac { | |
int veri; | |
struct Agac *solCocuk, *sagCocuk; | |
}; | |
//Fonksiyon Tanimlari | |
void dugum_ekle(struct Agac**, int); | |
void yaprak_yazdir(struct Agac*); | |
//dugum olusturma fonk. | |
void dugum_ekle(struct Agac**root, int value) { | |
struct Agac*new_node = (struct Agac*)malloc(sizeof(struct Agac)); | |
if (new_node) | |
{ | |
new_node->solCocuk = NULL; | |
new_node->sagCocuk = NULL; | |
new_node->veri = value; | |
if (*root) | |
{ | |
struct Agac*temp = *root; | |
while (temp) | |
{ | |
if (temp->veri >= value) | |
{ | |
if (temp->solCocuk != NULL) | |
{ | |
temp = temp->solCocuk; | |
} | |
else | |
{ | |
temp->solCocuk = new_node; | |
break; | |
} | |
} | |
else | |
{ | |
if (temp->sagCocuk != NULL) | |
{ | |
temp = temp->sagCocuk; | |
} | |
else | |
{ | |
temp->sagCocuk = new_node; | |
break; | |
} | |
} | |
} | |
} | |
else { | |
*root = new_node; | |
} | |
} | |
} | |
//yapraklari bulup yazdiran fonk. | |
void yaprak_yazdir(struct Agac*temp) { | |
if (temp) { | |
yaprak_yazdir(temp->solCocuk); | |
if (temp->solCocuk == NULL && temp->sagCocuk == NULL) { | |
printf(" %d", temp->veri); | |
} | |
yaprak_yazdir(temp->sagCocuk); | |
} | |
} | |
int main() | |
{ | |
int secim; | |
struct Agac*root = NULL; | |
while (1==1) | |
{ int eleman; | |
printf("\n --------------------------------------- \n"); | |
printf(" 1 --> Eleman Ekle \n"); | |
printf(" 2 --> Yaprak Dugumleri Yazdir \n"); | |
printf(" 3 --> EXIT \n"); | |
printf("---------------------------------------- \n"); | |
printf("Secimi girin: "); | |
scanf("%d", &secim); | |
switch (secim) { | |
case 1: | |
printf("Eklenecek eleman: "); | |
scanf("%d", &eleman); | |
dugum_ekle(&root, eleman); | |
break; | |
case 2: | |
if (root) { | |
printf("\n ---- Yaprak Dugumleri ----> "); | |
yaprak_yazdir(root); | |
} | |
else { | |
printf("\n--- Agac Bos ----"); | |
} | |
break; | |
case 3: | |
exit(0); | |
} | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment