Skip to content

Instantly share code, notes, and snippets.

@misterpoloy
Created August 18, 2020 05:31
Show Gist options
  • Save misterpoloy/c492d2a650e9c4d17d08b3b1eb4f746a to your computer and use it in GitHub Desktop.
Save misterpoloy/c492d2a650e9c4d17d08b3b1eb4f746a to your computer and use it in GitHub Desktop.
Node Depths
#include <cmath>
// Repasado 2 veces
using namespace std;
class BinaryTree {
public:
int value;
BinaryTree *left;
BinaryTree *right;
BinaryTree(int value) {
this->value = value;
left = NULL;
right = NULL;
}
};
int countNodeDepth(BinaryTree* root, int depth = 0) {
if (root == NULL) return 0;
int left = countNodeDepth(root->left, depth + 1);
int right = countNodeDepth(root->right, depth + 1);
return left + right + depth;
}
int nodeDepths(BinaryTree *root) {
return countNodeDepth(root);
}
@misterpoloy
Copy link
Author

misterpoloy commented Aug 18, 2020

Node Depths
aaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment