DS Sorting

Insertion

Insert function is used to add a new element in a binary search tree at appropriate location. Insert function is to be designed in such a way that, it must node violate the property of binary search tree at each value.

Allocate the memory for tree.

Set the data part to the value and set the left and right pointer of tree, point to NULL.

If the item to be inserted, will be the first element of the tree, then the left and right of this node will point to NULL.

Else, check if the item is less than the root element of the tree, if this is true, then recursively perform this operation with the left of the root.

If this is false, then perform this operation recursively with the right sub-tree of the root.