protected IBinaryTreeNode <ValueType> RotateRR(IBinaryTreeNode <ValueType> node) { IBinaryTreeNode <ValueType> newRoot = node.rightChild; node.SetRightChild(newRoot.leftChild); newRoot.SetLeftChild(node); return(newRoot); }
protected virtual IBinaryTreeNode <ValueType> RemoveLeft(IBinaryTreeNode <ValueType> node, ValueType value, RemovePrefer prefer) { IBinaryTreeNode <ValueType> leftMax = FindMax(node.leftChild); node.value = leftMax.value; node.SetLeftChild(Remove(node.leftChild, node.value, prefer)); return(node); }
void InitOutput(Transform tr, IBinaryTreeNode <Image> tImage, IBinaryTreeNode <Text> tText) { if (tr.childCount == 3) { Transform left = tr.GetChild(1); tImage.SetLeftChild(new BinaryTreeNode <Image>(left.GetComponent <Image>())); tText.SetLeftChild(new BinaryTreeNode <Text>(left.GetChild(0).GetComponent <Text>())); InitOutput(left, tImage.leftChild, tText.leftChild); Transform right = tr.GetChild(2); tImage.SetRightChild(new BinaryTreeNode <Image>(right.GetComponent <Image>())); tText.SetRightChild(new BinaryTreeNode <Text>(right.GetChild(0).GetComponent <Text>())); InitOutput(right, tImage.rightChild, tText.rightChild); } }
protected virtual IBinaryTreeNode <ValueType> Remove(IBinaryTreeNode <ValueType> node, ValueType value, RemovePrefer prefer) { if (node == null) { return(null); } int result = value.CompareTo(node.value); if (result < 0) { node.SetLeftChild(Remove(node.leftChild, value, prefer)); } else if (result > 0) { node.SetRightChild(Remove(node.rightChild, value, prefer)); } else { if (node.leftChild != null && node.rightChild != null) { if (prefer == RemovePrefer.Left) { RemoveLeft(node, value, prefer); } else if (prefer == RemovePrefer.Right) { RemoveRight(node, value, prefer); } else { return(null); } } else if (node.leftChild != null && node.rightChild == null) { RemoveLeft(node, value, prefer); } else if (node.leftChild == null && node.rightChild != null) { RemoveRight(node, value, prefer); } else { return(null); } } return(node); }
protected virtual IBinaryTreeNode <ValueType> Insert(IBinaryTreeNode <ValueType> node, ValueType value) { if (node == null) { return(new BinaryTreeNode <ValueType>(value)); } int result = value.CompareTo(node.value); if (result < 0) { node.SetLeftChild(Insert(node.leftChild, value)); } else if (result > 0) { node.SetRightChild(Insert(node.rightChild, value)); } return(node); }
protected IBinaryTreeNode <ValueType> RotateLR(IBinaryTreeNode <ValueType> node) { node.SetLeftChild(RotateRR(node.leftChild)); return(RotateLL(node)); }