Code:
printf("Name of Recipe: ");
fgets(recipename,29,stdin);
trim(recipename);
for(;;){
printf("Name of Ingredient: ");
fgets(name,29,stdin);
trim(name);
if(!strcmp(name,"")){
enter=0;
break;
}
printf("Quantity: ");
fgets(buff,29,stdin);
sscanf(buff,"%d",&quantity);
printf("Q_type: ");
fgets(buff,29,stdin);
sscanf(buff,"%c",&type);
rlocation = Recipesearch_tree(rtree, name);
if (!rlocation) {
/* not in tree, so insert the new word */
rtree = Rinsert_ingredient_order(rtree, name,quantity,type);
}
}
Code:
Recipe *Recipesearch_tree(Recipe *rtree, char *search_name) {
int compare;
if(rtree == NULL) {
return NULL;
}
else {
if((compare = strcmp(search_name, rtree->recipename)) == 0) {
return rtree; // node found
}
else if (compare < 0) {
return Recipesearch_tree(rtree->left, search_name);
}
else {
return Recipesearch_tree(rtree->right, search_name);
}
}
}
Code:
Recipe *rinsert_ingredient_order(Recipe *rtree, char *name,int quantity,char type){
Ingredient *tree1=NULL;
if (rtree == NULL) {
rtree =(Recipe*)malloc(sizeof(Recipe));
assert(rtree!=NULL);
rtree->recipename =(char *)malloc(strlen(name)+1);
while(tree1=insert_ingredient_order(tree1,name,quantity,type)=!NULL){
tree1=nsert_ingredient_order(tree1,name,quantity,type);
}
return rtree;
}

