Trees - Inserting in a binary search tree P92776


Statement
 

pdf   zip

thehtml

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 preorder traversal of the resulting tree.

Public test cases
  • Input

    30
    10
    50
    0
    100
    15
    50
    120
    30
    110
    

    Output

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