Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int proofRBCriterion2(TreeNode* node) {
- TreeNode* left = node->getLeft();
- TreeNode* right = node->getRight();
- int height;
- int add = 0;
- if (left == nullptr && right == nullptr) {
- return 0;
- }
- else if (left == nullptr) {
- height = proofRBCriterion2(right);
- if (right->isBlack()) {
- add = 1;
- }
- }
- else if (right == nullptr) {
- height = proofRBCriterion2(left);
- if (left->isBlack()) {
- add = 1;
- }
- }
- else {
- int leftHeight = proofRBCriterion2(left);
- int rightHeight = proofRBCriterion2(right);
- if (left->isBlack()) {
- leftHeight += 1;
- }
- if (right->isBlack()) {
- rightHeight += 1;
- }
- if (leftHeight != rightHeight) {
- return -1;
- }
- height = leftHeight;
- }
- if (height == -1) {
- return -1;
- }
- return height + add;
- }
Add Comment
Please, Sign In to add comment