123
This commit is contained in:
		
							parent
							
								
									2720d6cb38
								
							
						
					
					
						commit
						fb151e82f3
					
				@ -1,4 +1,4 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					/*#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct Node {
 | 
					typedef struct Node {
 | 
				
			||||||
    int data;
 | 
					    int data;
 | 
				
			||||||
@ -46,4 +46,67 @@ void build_tree() {
 | 
				
			|||||||
// Implementace funkce free_tree
 | 
					// Implementace funkce free_tree
 | 
				
			||||||
void free_tree() {
 | 
					void free_tree() {
 | 
				
			||||||
    // Zde implementujte uvolnění paměti použité pro strom
 | 
					    // Zde implementujte uvolnění paměti použité pro strom
 | 
				
			||||||
 | 
					}*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include <stdio.h> // Přidáno pro účely výstupu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct Node {
 | 
				
			||||||
 | 
					    int data;
 | 
				
			||||||
 | 
					    struct Node* left;
 | 
				
			||||||
 | 
					    struct Node* right;
 | 
				
			||||||
 | 
					} Node;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Node* newNode(int data);
 | 
				
			||||||
 | 
					Node* insert(Node* node, int data);
 | 
				
			||||||
 | 
					int search(Node* root, int x);
 | 
				
			||||||
 | 
					void build_tree();
 | 
				
			||||||
 | 
					void free_tree();
 | 
				
			||||||
 | 
					void sorted_data(); // Deklarace funkce sorted_data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Node* newNode(int data) {
 | 
				
			||||||
 | 
					    Node* node = (Node*)malloc(sizeof(Node));
 | 
				
			||||||
 | 
					    node->data = data;
 | 
				
			||||||
 | 
					    node->left = NULL;
 | 
				
			||||||
 | 
					    node->right = NULL;
 | 
				
			||||||
 | 
					    return node;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Node* insert(Node* node, int data) {
 | 
				
			||||||
 | 
					    if (node == NULL) {
 | 
				
			||||||
 | 
					        return newNode(data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					        if (data <= node->data) node->left = insert(node->left, data);
 | 
				
			||||||
 | 
					        else node->right = insert(node->right, data);
 | 
				
			||||||
 | 
					        return node;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int search(Node* root, int x) {
 | 
				
			||||||
 | 
					    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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Implementace funkce sorted_data
 | 
				
			||||||
 | 
					void sorted_data() {
 | 
				
			||||||
 | 
					    printf("Testovací funkce pro kontrolu správnosti řazení dat.\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main() {
 | 
				
			||||||
 | 
					    // Volání testů a jiné části kódu
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user