public NodeViewModel removeBST(NodeViewModel _nvm) { NodeViewModel removeNode = null; removeNode = _nvm; NodeViewModel parent = removeNode.getParent(); NodeViewModel[] children = removeNode.getChildren(); NodeViewModel replacementNode; if (children[LEFT] == null) { return removeNode; } else { replacementNode = children[LEFT].getMostRightNode(); for(;;) { children = replacementNode.getChildren(); removeNode.TxtOne = replacementNode.TxtOne; removeNode.Color = replacementNode.Color; removeNode.ColorOfText = replacementNode.ColorOfText; removeNode.PreColor = replacementNode.PreColor; if (children[LEFT] == null) return replacementNode; else { removeNode = replacementNode; replacementNode = children[LEFT].getMostRightNode(); } } } }
public bool checkCorrectParentToRoot(NodeViewModel nvm) { NodeViewModel grandParent = nvm.getParent(); NodeViewModel parent = nvm.getParent(); while (grandParent != root) { if (grandParent == null || grandParent.getParent() == null) break; grandParent = grandParent.getParent(); if (parent.X < grandParent.X && int.Parse(nvm.TxtOne) > int.Parse(grandParent.TxtOne) || parent.X > grandParent.X && int.Parse(nvm.TxtOne) <= int.Parse(grandParent.TxtOne)) return false; parent = parent.getParent(); } return true; }