1151 - CS I2P (II) 2017 Lee HW 3 Scoreboard

Time

2017/03/07 13:20:00 2017/06/19 00:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10962 Find Sum in a binary tree
11349 Binary Search Tree Traversal

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.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10962.c

Partial Judge Header

10962.h

Tags

10402Contest



Discuss




11349 - Binary Search Tree Traversal   

Description

Please create a binary search tree, and support insert operation. Please ignore the repeat number and print out the tree with preorder, inorder and postorder sequence. (The root node is greater than the node in the left subtree and smaller than the node in the right subtree.)

Pre-order:

  1. Check if the current node is empty / null.
  2. Display the data part of the root (or current node).
  3. Traverse the left subtree by recursively calling the pre-order function.
  4. Traverse the right subtree by recursively calling the pre-order function

In-order:

  1. Check if the current node is empty / null.
  2. Traverse the left subtree by recursively calling the in-order function.
  3. Display the data part of the root (or current node).
  4. Traverse the right subtree by recursively calling the in-order function.

Post-order:

  1. Check if the current node is empty / null.
  2. Traverse the left subtree by recursively calling the post-order function.
  3. Traverse the right subtree by recursively calling the post-order function.
  4. Display the data part of the root (or current node).

Input

The input contains two lines. The first line is a integer n (n<=8000) , and the second line is a sequence S, where S contain n non-negative integer number. (The first number in the sequence S is the root.) 

Output

Please print out the tree with preorder, inorder and postorder.(total three line)

Each line has '\n' in the end.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11349.c

Partial Judge Header

11349.h

Tags




Discuss