public void Insert(TI newItem) { TI currentNodeValue = NodeData; if (currentNodeValue.CompareTo(newItem) > 0) { if (LeftTree == null) { LeftTree = new Tree <TI>(newItem); } else { LeftTree.Insert(newItem); } } else { if (RightTree == null) { RightTree = new Tree <TI>(newItem); } else { RightTree.Insert(newItem); } } }
public void Insert(TItem newItem) { TItem currentNodeValue = NodeData; if (currentNodeValue.CompareTo(newItem) > 0) { //Insert the new item to left subtree if (LeftTree == null) { LeftTree = new Tree <TItem>(newItem); } else { LeftTree.Insert(newItem); } } else { //Insert the new item to right subtree if (RightTree == null) { RightTree = new Tree <TItem>(newItem); } else { RightTree.Insert(newItem); } } }
public void Insert(T item)//create method and pass parameter item { T currentNodeValue = NodeData; if ((currentNodeValue.CompareTo(item)) > 0) { if (LeftTree == null) { LeftTree = new BST <T>(item); } else { LeftTree.Insert(item); } } else { if (RightTree == null) { RightTree = new BST <T>(item); } else { RightTree.Insert(item); } } }