123
This commit is contained in:
parent
3f261da232
commit
3672ec8734
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user