diff --git a/src/cw8/count_symmetrical_nodes.c b/src/cw8/count_symmetrical_nodes.c index 2d63c97..6bb7d64 100644 --- a/src/cw8/count_symmetrical_nodes.c +++ b/src/cw8/count_symmetrical_nodes.c @@ -3,8 +3,7 @@ policz węzły drzewa które mają tyle samo kroków do korzenia co do najgłębszego liścia */ - -#include +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) typedef struct bin_tree bin_tree; diff --git a/src/cw8/zad10/is_ultraleftist.c b/src/cw8/zad10/is_ultraleftist.c new file mode 100644 index 0000000..c2bfa2b --- /dev/null +++ b/src/cw8/zad10/is_ultraleftist.c @@ -0,0 +1,23 @@ +#include + +typedef struct node* bin_tree; + +struct node { + int val; + bin_tree left, right; +}; + +bool is_ultraleftist(bin_tree t, int depth, int* depth_last) { + if (!t) return true; + + if (!t->left && !t->right) { + if (*depth_last < depth) + return false; + + *depth_last = depth; + return true; + } + + return is_ultraleftist(t->left, depth + 1, depth_last) + && is_ultraleftist(t->right, depth + 1, depth_last); +} \ No newline at end of file diff --git a/src/cw8/zad12/cut_tree_into_two.c b/src/cw8/zad12/cut_tree_into_two.c new file mode 100644 index 0000000..a541876 --- /dev/null +++ b/src/cw8/zad12/cut_tree_into_two.c @@ -0,0 +1,10 @@ +typedef struct node* bin_tree; + +struct node { + int val; + bin_tree left, right; +}; + +// policz rozmiar drzewa: int size + +// przejdź przez drzewo postorderem \ No newline at end of file diff --git a/src/cw8/zad7/general_tree.c b/src/cw8/zad7/general_tree.c new file mode 100644 index 0000000..e69de29 diff --git a/src/cw8/zad8/jump_traversal.c b/src/cw8/zad8/jump_traversal.c index e16a3ca..384bac5 100644 --- a/src/cw8/zad8/jump_traversal.c +++ b/src/cw8/zad8/jump_traversal.c @@ -1,5 +1,3 @@ -#include - typedef struct bin_tree bin_tree; struct bin_tree {