| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10962 | Find Sum in a binary tree |
|
Description
Given a binary tree, print the sum of nodes in the tree.
This problem will give you the inorder and preorder sequences to build a tree, and you have to write a function to count the sum of nodes in the tree. To solve this problem, you can write a recursive function to traverse the tree and sum up the data of nodes.
You will be provided with main.c and function.h. main.c contains the implementation of functions which build a tree by the inorder and preorder, and function.h contains the definition of tree node. You only need to implement Sum(Node *root) and print the sum in function.c.
For OJ submission:
Step 1. Submit only your function.c into the submission block.(Please choose C compiler)
Step 2. Check the results and debug your program if necessary.
main.c
function.h
Input
The input contains three lines. The first line is the number of nodes in the tree. The second line is the inorder and the third line is the preorder of the tree.
Output
The output is the sum of nodes in the tree.