$24
Description
Please implement a tree (each node contains a 32bit signed integer) with six functions: “constructTree”, “deleteTree”, “treeHeight”, “treeWeight”, “leafNum” and “minPathWeight”.
Node* constructTree (Node *root, std::string treeStr) const;
A function can construct tree based on the treeStr which is an S-expression, and return a Node* that points to the root of tree.
Node* deleteTree (Node *root) const;
Delete the tree and release the memory allocation of each node, then return a nullptr.
int treeHeight (const Node *root) const;
Return the height of tree.
int treeWeight (const Node *root) const;
Return the sum of node weights in a tree.
int leafNum (const Node *root) const;
Return the leaf node number in a tree.
int maxPathWeight (const Node *root) const;
Return the min weight from root to leaf in a tree.
Implement these functions in MyBinaryTreeOps.cpp and MyBinaryTreeOps.h.
Don’t try to modify files in readonly, since we will replace them and use stricter testing.
We provide a basic testing file 1.in in readonly and you can use it to evaluate correctness of your code.
Make sure your code can pass basic testing.
Note
Each of the 3 hidden test cases contains up to 10,000 trees and each tree may have 1,000 of nodes.
The time limit is “60” second.
Note: To get at least 60 points, you have to implement all the functionalities mentioned above. Always outputting the hard-coded results of the sample input without other implementations with get 0 points.
Input
The input is a S-Expression for a tree.
E.g.:(99(5()())(35(-5()())()))
Output
If your code is correct, the output will be “[Accepted]”.