根是黑的吗
同一棵树。
运行下面这段程序:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
struct RNode {
int val;
string color;
RNode* left = nullptr;
RNode* right = nullptr;
};
RNode* rb_tree() {
RNode* root = new RNode{17, "黑"};
root->left = new RNode{15, "红"};
root->right = new RNode{24, "黑"};
root->left->left = new RNode{13, "红"};
return root;
}
int main() {
cout << boolalpha << (rb_tree()->color == "黑") << endl;
}
(本题用 g++ -std=c++17 -O0 编译。)
全部评论