-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e460e5
commit 0e30e37
Showing
3 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
policz węzły drzewa które mają tyle samo kroków do korzenia | ||
co do najgłębszego liścia | ||
*/ | ||
|
||
|
||
#include <stdlib.h> | ||
|
||
typedef struct bin_tree bin_tree; | ||
|
||
struct bin_tree { | ||
int data; | ||
bin_tree* left; | ||
bin_tree* right; | ||
}; | ||
|
||
int count_symmetrical(bin_tree *t, int depth, int* max_depth) { | ||
if (!t) { | ||
*max_depth = -1; | ||
return 0; | ||
} | ||
|
||
int max_depth_left, max_depth_right, count = 0; | ||
count += count_symmetrical(t->left, depth+1, &max_depth_left); | ||
count += count_symmetrical(t->right, depth+1, &max_depth_right); | ||
|
||
*max_depth = 1 + max(max_depth_left, max_depth_right); | ||
if (*max_depth == depth) ++count; | ||
return count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdlib.h> | ||
|
||
typedef struct bin_tree bin_tree; | ||
|
||
struct bin_tree { | ||
int data; | ||
bin_tree* left; | ||
bin_tree* right; | ||
}; | ||
|
||
void visit(bin_tree *t) {} | ||
|
||
void jump_traversal(bin_tree *t, int depth_mod2) { | ||
if (!t) return; | ||
|
||
if (depth_mod2) visit(t); | ||
jump_traversal(t->left, 1 - depth_mod2); | ||
jump_traversal(t->right, 1 - depth_mod2); | ||
if (!depth_mod2) visit(t); | ||
} | ||
|
||
int main() { | ||
bin_tree t; | ||
jump_traversal(&t, 0); | ||
} |