Insert in a BST

A binary search tree (BST) is a binary tree such that for each node n in
the tree the elements in the left subtree of the tree rooted at n are
less than the element at node n, and the elements of the right subtree
of the tree rooted at n are greater than the element at the node n.

Write a program that reads a sequence of integer numbers and builds a
binary search tree by inserting the numbers in the sequence in an empty
tree. The numbers are inserted in the order they appear in the sequence.
If a number is already in the tree, insertion has no effect in the tree,
otherwise the number is inserted in a spot that guarantees that the
resulting tree is a BST.

The program must write the BST resulting from inserting the numbers in
the input sequence in pre-order.

Problem information

Author: Josefina Sierra Santibáñez

Generation: 2026-01-25T20:02:51.437Z

© Jutge.org, 2006–2026.
https://jutge.org
