11227 - HW3-Trees   

Description

//----------------------------------------------------------------------

// Input a tree string in S-expression, construct the tree and

// return the pointer to its root node.

//----------------------------------------------------------------------

virtual Node* constructTree(Node *root, std::string treeStr)const;

 

//----------------------------------------------------------------------

// Delete and release the memory allocation of each node, and

// return a nullptr.

//----------------------------------------------------------------------

virtual Node* deleteTree(Node *root)const;

 

//----------------------------------------------------------------------

// Return the height of the tree.

//----------------------------------------------------------------------

virtual int treeHeight(const Node *root)const;

 

//----------------------------------------------------------------------

// Return the sum of node weights.

//----------------------------------------------------------------------

virtual int treeWeight(const Node *root)const;

 

//----------------------------------------------------------------------

// Return the number of leaf nodes.

//----------------------------------------------------------------------

virtual int leafNum(const Node *root)const;

 

//----------------------------------------------------------------------

// Return the max path weight from root to leaf.

//----------------------------------------------------------------------

virtual int maxPathWeight(const Node *root)const;

Input

There are many binary trees in the input. Each tree occupies a line, and is expressed in S-expression.

Output

For each tree, output treeHeight, treeWeight, leafNum, maxPathWeight in a line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11227.cpp

Partial Judge Header

11227.h

Tags




Discuss