public void GetSizeOfEmptyTree() { BinaryTree <int> tree = new BinaryTree <int>(); Assert.AreEqual(0, tree.Size()); }
public void BreadthFirstOnEmptyTree() { BinaryTree <int> tree = new BinaryTree <int>(); tree.BreadthFirstSearch(0); }
public void DepththFirstOnEmptyTree() { BinaryTree <int> tree = new BinaryTree <int>(); tree.DepthFirstSearch(0); }
public void RootIsNull() { BinaryTree <int> tree = new BinaryTree <int>(); Assert.IsNull(tree.Root); }
public void CanCreateTree() { BinaryTree <int> tree = new BinaryTree <int>(); Assert.IsNotNull(tree); }
public BinaryTreeTests() { _sut = new BinaryTree <int>(_testData); }
/// <summary> /// Удаляет узел из дерева /// </summary> /// <param name="node">Удаляемый узел</param> public void Remove(BinaryTree node) { if (node == null) { return; } var me = MeForParent(node); //Если у узла нет дочерних элементов, его можно смело удалять if (node.Left == null && node.Right == null) { if (me == BinSide.Left) { node.Parent.Left = null; } else { node.Parent.Right = null; } return; } //Если нет левого дочернего, то правый дочерний становится на место удаляемого if (node.Left == null) { if (me == BinSide.Left) { node.Parent.Left = node.Right; } else { node.Parent.Right = node.Right; } node.Right.Parent = node.Parent; return; } //Если нет правого дочернего, то левый дочерний становится на место удаляемого if (node.Right == null) { if (me == BinSide.Left) { node.Parent.Left = node.Left; } else { node.Parent.Right = node.Left; } node.Left.Parent = node.Parent; return; } //Если присутствуют оба дочерних узла //то правый ставим на место удаляемого //а левый вставляем в правый if (me == BinSide.Left) { node.Parent.Left = node.Right; } if (me == BinSide.Right) { node.Parent.Right = node.Right; } if (me == null) { var bufLeft = node.Left; var bufRightLeft = node.Right.Left; var bufRightRight = node.Right.Right; node.Data = node.Right.Data; node.Right = bufRightRight; node.Left = bufRightLeft; Insert(bufLeft, node, node); } else { node.Right.Parent = node.Parent; Insert(node.Left, node.Right, node.Right); } }
public BinaryTreeTests() { _sut = new BinaryTree <int> { 8, 5, 12, 3, 7, 10, 15 }; }
public void ConstructorRoot() { BinaryTree <int> intTree = new BinaryTree <int>(); Assert.IsNull(intTree.Root); }