-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequal-paths.h
More file actions
33 lines (29 loc) · 872 Bytes
/
equal-paths.h
File metadata and controls
33 lines (29 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//-----------------------------------------
// You may NOT change anything in this file
//-----------------------------------------
#ifndef EQUAL_PATHS_H
#define EQUAL_PATHS_H
#ifndef RECCHECK
#include <cstdlib>
#endif
struct Node {
int key;
Node *left, *right;
// Constructor for convenience
Node(int k, Node* lt = nullptr, Node* rt = nullptr) :
key(k), left(lt), right(rt)
{}
};
/**
* @brief Returns true if all paths from leaves to root are the same length (height),
* and false otherwise
*
* Note: this doesn't mean we are checking if the tree is full, but just that
* any leaf node (wherever it may exist) has the same length path to the root
* as all others.
*
* @param root Pointer to the root of the tree to check for equal paths
*/
bool equalPaths(Node * root);
int height(Node* root);
#endif