diff --git a/a3/binary_search_tree.c b/a3/binary_search_tree.c index 45ef99c..c1463eb 100644 --- a/a3/binary_search_tree.c +++ b/a3/binary_search_tree.c @@ -6,6 +6,10 @@ typedef struct Node { struct Node* right; } Node; +Node* newNode(int data); +Node* insert(Node* node, int data); +int search(Node* root, int x); + Node* newNode(int data) { Node* node = (Node*)malloc(sizeof(Node)); node->data = data; @@ -26,7 +30,8 @@ Node* insert(Node* node, int data) { } int search(Node* root, int x) { - if(root == NULL || root->data == x) return root; + if(root == NULL) return 0; + if(root->data == x) return 1; else if(root->data < x) return search(root->right, x); else return search(root->left, x); }