private AssociativeTreeNode <T> FindPrev(AssociativeTreeNode <T> treeNode, AssociativeTreeNode <T> nodeForSearch) { if (treeNode != null) { var leftNode = (treeNode.Left != -1) ? AssociativeTreeNodes[treeNode.Left] : null; var rightNode = (treeNode.Right != -1) ? AssociativeTreeNodes[treeNode.Right] : null; if (nodeForSearch > treeNode) { return(nodeForSearch.Equals(rightNode) ? treeNode : FindPrev(rightNode, nodeForSearch)); } else if (nodeForSearch < treeNode) { return(nodeForSearch.Equals(leftNode) ? treeNode : FindPrev(leftNode, nodeForSearch)); } } throw new TreeException("Can't Find the node!"); }
public void DeleteNode(AssociativeTreeNode <T> treeNode) { if (treeNode.Equals(Root)) { DeleteRoot(); } else { DeleteNode(Root, treeNode); } DeleteInArray(treeNode); }
private int FindIndexOfNode(AssociativeTreeNode <T> nodeForSearch) { int index = -1; for (int i = 0; i < Count && (index == -1); i++) { if (nodeForSearch.Equals(AssociativeTreeNodes[i])) { index = i; } } return(index); }
private bool Contains(AssociativeTreeNode <T> treeNode, AssociativeTreeNode <T> nodeForSearch) { if (treeNode != null) { var rightNode = (treeNode.Right != -1) ? AssociativeTreeNodes[treeNode.Right] : null; var leftNode = (treeNode.Left != -1) ? AssociativeTreeNodes[treeNode.Left] : null; if (nodeForSearch > treeNode) { return(Contains(rightNode, nodeForSearch)); } else if (nodeForSearch < treeNode) { return(Contains(leftNode, nodeForSearch)); } } return(treeNode != null && treeNode.Equals(nodeForSearch)); }
private void DeleteNode(AssociativeTreeNode <T> treeNode, AssociativeTreeNode <T> nodeForRemove) { if (treeNode != null) { var rightNode = (treeNode.Right != -1) ? AssociativeTreeNodes[treeNode.Right] : null; var leftNode = (treeNode.Left != -1) ? AssociativeTreeNodes[treeNode.Left] : null; if (nodeForRemove > treeNode) { DeleteNode(rightNode, nodeForRemove); } else if (nodeForRemove < treeNode) { DeleteNode(leftNode, nodeForRemove); } else if (nodeForRemove.Equals(treeNode)) { RemoveFromNodeOperation(treeNode); } } }