Inserting value to a sorted binary tree?
Just read this binary trees explanation (well, read it again, I read it ages ago and forgot it since I don't code much)
I think I understand it, but I'm not sure about one thing.
If you have a sorted tree and call insert(X) on the tree, it will find the appropriate location for it(by repeatedly travelling left or right until it finds an empty node, based on whether it's bigger or smaller than current one), and then insert it.
This should keep the tree sorted (I think anyway), but not balanced (obviously).
But if I called insert(7) on:
I'd get the 7 being placed to the left of the 8, and the tree would no longer be sorted.
Is there a way of doing the insertion while keeping the tree sorted or would it just have to be resorted on such occurences?
(Which I guess wouldn't be too bad considering you'd only really have to resort the tree with root node at 8 AFAICT, not whole thing)