This commit is contained in:
Macko 2024-04-18 15:00:57 +02:00
parent 3f261da232
commit 3672ec8734

View File

@ -6,6 +6,10 @@ typedef struct Node {
struct Node* right; struct Node* right;
} Node; } Node;
Node* newNode(int data);
Node* insert(Node* node, int data);
int search(Node* root, int x);
Node* newNode(int data) { Node* newNode(int data) {
Node* node = (Node*)malloc(sizeof(Node)); Node* node = (Node*)malloc(sizeof(Node));
node->data = data; node->data = data;
@ -26,7 +30,8 @@ Node* insert(Node* node, int data) {
} }
int search(Node* root, int x) { 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 if(root->data < x) return search(root->right, x);
else return search(root->left, x); else return search(root->left, x);
} }