12052 - DS_2018Fall_Homework3   

Description

In this homework, we need to construct a tree from the s-expression and implement the following functions.

Construct_tree

Tree traversal

Tree height

Weight sum

Maximum Path Sum

Invert

Input

Input will be a string, which is an s-expression of a binary tree

e.g. (1(2(4()())(5()()))(3(6()())(7()())))

 

-100 <= Node weight <= 100

Output

After constructing the tree, you have to print the following information of this tree.

  • In-order traversal
  • Pre-order traversal
  • Post-order traversal
  • Level-order traversal
  • Height of tree
  • Weight sum of tree
  • Maximum path sum of tree
  • In-order traversal after inverting
  • Pre-order traversal after inverting
  • Post-order traversal after inverting
  • Level-order traversal after inverting

Sample Input  Download

Sample Output  Download

Partial Judge Code

12052.cpp

Partial Judge Header

12052.h

Tags




Discuss