Exemplo n.º 1
0
BusinessNode * tree_search_name(char * name, BusinessNode * root)
{
  if (strcmp(root -> name, name) == 0) return root;
  else if (strcmp(root -> name, name) < 0 && root -> right != NULL)//name is bigger than current name, search in the right branch
    return tree_search_name(name, root -> right);
  else if (root -> left != NULL)
    return tree_search_name(name, root -> left);
  return NULL;
}
Exemplo n.º 2
0
int main(void)
{
	void print_tree2(BusinessNode * tree,int i);
	printf("\e[1;1H\e[2J"); // clears screen
	//BusinessNode *Node,*Node1, *Node2, *Node3, *Node4, *Holder;
	
	//Node = create_node(strdup("4.5"),strdup("Awesome Business"),strdup("Purdue"));
	//Node1 = create_node(strdup("3.2"),strdup("Yummy"),strdup("here"));
	//Node2 = create_node(strdup("3.9"),strdup("K"),strdup("There"));
	//Node3 = create_node(strdup("5.0"),strdup("La sta"),strdup("DC"));
	//Node4 = create_node(strdup("0.9"),strdup("App"),strdup("Gary"));
	
	
	//print_node(Node);
	//print_node(Node1);
	//print_node(Node2);
	//print_node(Node3);
	//print_node(Node4);
	//printf("\n------------\n");

	//Holder = tree_insert(Node1,Node);
	//Holder = tree_insert(Node2,Node);
	//Holder = tree_insert(Node3,Node);
	//Holder = tree_insert(Node4,Node);
	//print_tree2(Holder,0);
	//destroy_tree(Holder);
	
	BusinessNode *SmallFile = load_tree_from_file("yelp_businesses.tsv");
	print_tree2(SmallFile,0);
	printf("%p\n",(tree_search_name("Oriental Supermarket", SmallFile)));
	destroy_tree(SmallFile);
	
	
	return EXIT_SUCCESS;
}
Exemplo n.º 3
0
/* Search a BusinessNode BST for the node with the name 'name'. Returns
 * pointer to the node with a match.
 *
 * If there is no match, return NULL.
 */
BusinessNode *
tree_search_name(char * name, BusinessNode * root){
	if(root != NULL){
		int comp = strcmp(name, root -> name);
		if(comp == 0){
			return root;
		}
		else 
			if(comp <= 0){
				root = tree_search_name(name,root->left);
			}
			else{
				root = tree_search_name(name,root->right);
			}
		return root;
	}
	return NULL;
}
Exemplo n.º 4
0
/* Search a BusinessNode BST for the node with the name 'name'. Returns
 * pointer to the node with a match.
 *
 * If there is no match, return NULL.
 */
BusinessNode * tree_search_name(char * name, BusinessNode * root)
{
	if (root == NULL)
	{
		return (NULL);
	} else if (strcmp(root -> name, name) == 0)
	{
		return (root);
	} else if (strcmp(root -> name, name) < 0)
	{
		root = tree_search_name(name, root -> right);
		return (root);
	} else
	{
		root = tree_search_name(name, root -> left);
		return (root);
	}
}
Exemplo n.º 5
0
BusinessNode * tree_search_name(char * name, BusinessNode * root)
{
    if(name == NULL)
	return NULL;

    if(root == NULL)
	return NULL;

    int comp = strcmp(name, root -> name);

    if(comp == 0)
	return root;

    if(comp > 0)
	return tree_search_name(name, root -> right);

    return tree_search_name(name, root -> left);	
}
Exemplo n.º 6
0
//// EXAMINE THAT TREE ///////////////////////////////////////////////////////
BusinessNode *tree_search_name(char * name, BusinessNode * root){


  if(root == NULL){
    printf("reached end, or was passed a NULL tree: returning a NULL pointer.\n");
    return NULL;
  }
if(strcmp(name, root->name)==0)
  {
    printf("The Companys have the same name, Company found!\n");
    return root;
  }
  if(strcmp(name,root->name)<0){
      printf("moving left on the tree...\n");
      return tree_search_name(name, root->left);
  }
    printf("moving right on the tree...\n");
    return tree_search_name(name, root->right);
}
Exemplo n.º 7
0
/* Search a BusinessNode BST for the node with the name 'name'. Returns
 * pointer to the node with a match.
 *
 * If there is no match, return NULL.
 */
BusinessNode * tree_search_name(char * name, BusinessNode * root)
{
    if(root == NULL)
    {
        return (NULL);
    }
    int val=0;
    val = strcmp(name, root->name);
    if (val == 0)
    {
        return(root);
    }
    else if(val < 0)
    {
        return(tree_search_name(name, root->left));
    }
    else
    {
        return(tree_search_name(name, root->right));
    }
}
Exemplo n.º 8
0
BusinessNode * tree_search_name(char * name, BusinessNode * root)
{
  BusinessNode * temp = root;
  
  if (root == NULL)
  {
    return NULL;
  }
  printf("Current name: %s\n",root -> name);
  if (strcmp(root -> name,name) == 0)
  {
    return root;
  }
  if (strcmp(root -> name,name) > 0)
  {
    temp = tree_search_name(name,root -> left);
  }
  else
  {
    temp = tree_search_name(name,root -> right);
  }
  return temp;
}