From 3672ec8734b6bbbdcc2e79ab8a79390c786e480a Mon Sep 17 00:00:00 2001 From: Miloslav Macko Date: Thu, 18 Apr 2024 15:00:57 +0200 Subject: [PATCH] 123 --- a3/binary_search_tree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); }