123
This commit is contained in:
parent
3672ec8734
commit
2720d6cb38
@ -9,23 +9,25 @@ typedef struct Node {
|
|||||||
Node* newNode(int data);
|
Node* newNode(int data);
|
||||||
Node* insert(Node* node, int data);
|
Node* insert(Node* node, int data);
|
||||||
int search(Node* root, int x);
|
int search(Node* root, int x);
|
||||||
|
void build_tree(); // Deklarace funkce build_tree
|
||||||
|
void free_tree(); // Deklarace funkce free_tree
|
||||||
|
|
||||||
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;
|
||||||
node->left = NULL;
|
node->left = NULL;
|
||||||
node->right = NULL;
|
node->right = NULL;
|
||||||
return(node);
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* insert(Node* node, int data) {
|
Node* insert(Node* node, int data) {
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
return(newNode(data));
|
return newNode(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (data <= node->data) node->left = insert(node->left, data);
|
if (data <= node->data) node->left = insert(node->left, data);
|
||||||
else node->right = insert(node->right, data);
|
else node->right = insert(node->right, data);
|
||||||
return(node);
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,3 +37,13 @@ int search(Node* root, int x) {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementace funkce build_tree
|
||||||
|
void build_tree() {
|
||||||
|
// Zde implementujte vytvoření stromu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementace funkce free_tree
|
||||||
|
void free_tree() {
|
||||||
|
// Zde implementujte uvolnění paměti použité pro strom
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user