struct node * insert2(struct node *root, char x[],char id[]) { if(!root) { root=(struct node*)malloc(sizeof(struct node)); free( root->data ); // free previously allocated memory, if any root->data = strdup( x ); // malloc and copy root->id=id; root->left = NULL; root->right = NULL; // printf("1\n"); return(root); } if(atoi(root->id) > atoi(id)){ root->left = insert(root->left,x,id); } else { if(atoi(root->id) < atoi(id)) root->right = insert(root->right,x,id); } return(root); }