#include "stdio.h"
#include "conio.h"
#include "alloc.h"
struct bsts_node {
bsts_node *left;
bsts_node *right;
int data;
};
struct bsts_node *tmalloc(size_t size){
struct bsts_node *p;
if(p ==NULL)
else return p;
}
struct bsts_node *createnode(size_t size){
struct bsts_node *n;
n = tmalloc(size);
n->left=n->right=NULL;
return n;
}
void bsts_insert(bsts_node *node_root,int datanew){
struct bsts_node *p;
p=node_root;
if(node_root == NULL) {
node_root=createnode(sizeof(bsts_node));
node_root->data = datanew;
}
else {
while(p!=NULL){
if(datanew == p->data) return;
else{
if(datanew > p->data) p=p->right;
else p=p->left;
}
}
p=createnode(sizeof(bsts_node));
p->data= datanew;
}
}
void printfPreorder(struct bsts_node *node_root){
if(node_root !=NULL) {
printf("%d\n",node_root
->data
); printfPreorder(node_root->left);
printfPreorder(node_root->right);
}
}
void main(){
struct bsts_node *root=createnode(sizeof(bsts_node));
root->data= 25;
int i;
for(i=1;i<=50;i++){
bsts_insert(root,i);
}
printfPreorder(root);
getch();
}