//Binary Tree - Insertion Using C – 32 PPT – Albert Hendry Harsono (1701296914)
#include <stdio.h>
#include <stdlib.h>
struct tnode{
int value;
struct tnode *left;
struct tnode *right;
}*leaf;
void insert(int key, struct tnode **leaf){
if( *leaf == 0 )
{
*leaf = (struct tnode*) malloc( sizeof( struct tnode ) );
(*leaf)->value = key;
(*leaf)->left = 0;
(*leaf)->right = 0;
}
else if(key < (*leaf)->value)
{
insert( key, &(*leaf)->left );
}
else if(key > (*leaf)->value)
{
insert( key, &(*leaf)->right );
}
}
void main(){
int z=0;
int key=0;
struct tnode *root = 0;
do{
system("cls");
printf("Masukan banyak data yang akan diinput[1..10]: ");
scanf("%d",&z);fflush stdin;
}while(z<1||z>10);
for(int p=0; p<z; p++){ do{ system("cls"); printf("Masukan data ke-%d: ",p+1); scanf("%d",&key); fflush stdin; }while(key>50||key<1);
insert(key,&leaf);
}
}