12051 - Tsai_DS_1101 Binary Search Tree   

Description

Implement a binary search tree (BST) with the following applications:

1. Insert: Insert a node into the BST.

2. PrintInorder: Print the BST in inorder traversal method.

Hint: The output should be a sorted list of numbers.

3. Delete: Delete a specific node from the tree.

 

Note: You should NOT use any related STL or sort function when implementing the BST.

Input

There are multiple lines in the input.

The first line contains an integer N (0 < N <= 1000), indicating the number of instructions.

According to the different instructions, operating the different tasks.

 

Input format:

Insert + integer //e.g: Insert 15

Delete + integer //e.g: Delete 15

Print

 

Note: The integer would be in the range of -10000 < integer < 10000

Hint: The first five test cases did not contain the "Delete" instruction.

Output

In "Print" command, you should output a space blank after every number.

You need to print '\n' at the end of a line.

Sample Input  Download

Sample Output  Download

Tags




Discuss