Implementation of insert and delete for a ternary tree.