Skip to content

Instantly share code, notes, and snippets.

@hasanaydins
Created October 28, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasanaydins/fa95bcbee62af378f12ff47014b447d3 to your computer and use it in GitHub Desktop.
Save hasanaydins/fa95bcbee62af378f12ff47014b447d3 to your computer and use it in GitHub Desktop.
SizzlingThisTest created by HasanAydin - https://repl.it/@HasanAydin/SizzlingThisTest
//
//
// 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