#include<stdio.h> #include<stdlib.h> #include<conio.h> struct node { int element; struct node* left; struct node* right; }; typedef struct node* ptrtonode; typedef ptrtonode searchtree; typedef ptrtonode position; /* struct treenode { int Element; treenode *Left; treenode *Right; }; typedef struct treenode *PtrToNode; typedef struct *PtrToNode searchtree; typedef struct *PtrToNode Position; searchtree tree(int x,searchtree T); void preorder(searchtree T); */ searchtree tree(int x,searchtree T); void preorder(searchtree T); int main() { int T=NULL; freopen("inp.txt","r",stdin); // freopen("out.txt","w",stdout); int c,i=0; int array[100]; while((scanf("%d",&c))!=EOF) { array[i++]=c; //printf("%d",c); tree(c,T); } preorder(T); return 0; } searchtree tree(int x,searchtree T) { //searchtree T; if(T==NULL) { T=malloc(sizeof(struct node)); T->element=x; T->left=NULL; T->right=NULL; } else if(T!=NULL) { if(x<t->element) { T->left=tree(x,T->left); } else if(x>T->right) { T->right=tree(x,T->right); } } } void preorder(searchtree T) { if(T!=NULL) { printf("%d",T->element); preorder(T->left); preorder(T->right); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)