#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct treeentry{
int key;
}TreeEntry;
typedef struct node{
TreeEntry entry;
struct node *left;
struct node *right;
}Node;
typedef struct tree{
Node *root;
}Tree;
void CreateTree(Tree *T){
T->root=NULL;
}
void PreorderTraverse(Node *root,void(*visit)(TreeEntry)){
if(root!=NULL)
{
visit(root->entry);
PreorderTraverse(root->left,visit);
PreorderTraverse(root->right,visit);
}
}
void InorderTraverse(Node *root,void(*visit)(TreeEntry)){
if(root)
{
InorderTraverse(root->left,visit);
visit(root->entry);
InorderTraverse(root->right,visit);
}
}
void PostorderTraverse(Node *root,void(*visit)(TreeEntry)){
if(root)
{
PostorderTraverse(root->left,visit);
PostorderTraverse(root->right,visit);
visit(root->entry);
}
}
Node *Makenode(TreeEntry t){
Node *np;
if((np=(Node*)malloc(sizeof(Node)))==NULL)
printf("no place");
else{
np->entry=t;
np->left=NULL;
np->right=NULL;
}
return np;
}
Node *InsertTree(Node *root,Node *newnode){
if(root==NULL)
root=newnode;
else if(newnode->entry.key<root->entry.key)
root->left=InsertTree(root->left,newnode);
else
root->right=InsertTree(root->right,newnode);
return root;
}
void print(TreeEntry t){
printf("%d ",t);
}
int main(){
int i;
Tree T;
Node *newnode;
TreeEntry item;
CreateTree(&T);
printf("5 sayi girin:\n");
for(i=0;i<5;i++){
scanf("%d",&item.key);
newnode=Makenode(item);
T.root=InsertTree(T.root,newnode);
}
printf("preorder:");
PreorderTraverse(T.root,print);
printf("\ninorder:");
InorderTraverse(T.root,print);
printf("\npostorder:");
PostorderTraverse(T.root,print);
return 0;
}