Code:
struct node
{
char string[20];
struct node *left;
struct node *right;
}
addnode(struct node **tree,char *str){
struct node *temp;
temp=(struct node *)malloc( sizeof( struct node ) );
memcpy (temp->string,str,strlen(str)+1);
if(*tree==NULL){
(*tree=temp);
}
else { (((*tree)->left)=temp);(*tree=temp);}
}
main(){
struct node root ;
struct node *tree=NULL;
struct node **tree_p;
tree_p= &tree;
FILE *in=fopen("c:\\str6.txt","r");
char *str=(char *)malloc(30);
for(int inc=1;inc<=10;inc++){
fscanf(in,"%s",str);
addnode(tree_p,str,start);
}
}
addnode function updates tree to point to the latest position.
how do i get to the root now?
please advise me over this,i am just learning tree's and i have very little experience on how to creat functions for handling tree's.
this tree is being used as link list,that is why only adding to the left.