From 641cf74afc8466fe4d0753313a18f5c64a3c34f7 Mon Sep 17 00:00:00 2001 From: mgisr Date: Sat, 3 Dec 2022 17:17:58 +0800 Subject: [PATCH] feat(codes/cpp/include/TreeNode.cpp): add 'parent' and 'height' field --- codes/cpp/include/TreeNode.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/codes/cpp/include/TreeNode.hpp b/codes/cpp/include/TreeNode.hpp index 7be2b8d..18bb894 100644 --- a/codes/cpp/include/TreeNode.hpp +++ b/codes/cpp/include/TreeNode.hpp @@ -11,10 +11,13 @@ * */ struct TreeNode { - int val; - TreeNode *left; - TreeNode *right; - TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + int val{}; + int height = 1; + TreeNode *parent{}; + TreeNode *left{}; + TreeNode *right{}; + TreeNode() = default; + explicit TreeNode(int x, TreeNode *parent = nullptr) : val(x), parent(parent) {} }; /**