Inserting in a binary search tree P94818


Statement
 

pdf   zip

html

Write a program that forms a binary search tree from a given sequence of natural numbers. Each new integer must be placed at the only leaf that allows to mantain the propierty of the binary search trees. The repeated elements must be ignored.

Input

Input is a non empty sequence of natural numbers.

Output

Your program must print the resulting tree, following the same format of the instances (which is the same that the format of the exercise : “”, but now with natural numbers).

Public test cases
  • Input

    30
    10
    50
    0
    100
    15
    50
    120
    30
    110
    

    Output

                                         120
                                                   110
                               100
                      50
            30
                                15
                      10
                                 0
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++