You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
492 B
24 lines
492 B
#include <stdlib.h>
|
|
#include "bin-trees.h"
|
|
|
|
tree_ptr
|
|
new_node (int value)
|
|
{
|
|
tree_ptr node = (tree_ptr) malloc (sizeof (tree_ptr));
|
|
node->data = value;
|
|
node->left = NULL;
|
|
node->right = NULL;
|
|
return node;
|
|
}
|
|
|
|
void
|
|
search_tree_insert (tree_ptr *root, int value)
|
|
{
|
|
if (*root == NULL)
|
|
*root = new_node (value);
|
|
else if (value < (*root)->data)
|
|
search_tree_insert (&((*root)->left), value);
|
|
else if (value > (*root)->data)
|
|
search_tree_insert (&((*root)->right), value);
|
|
}
|