public void TestLeafs() { var root = new Node(3); var adder = new SortTreeChildNodeAdder(root); Assert.Test(root.Leafs == 1); adder.AddChildNode(2); Assert.Test(root.Leafs == 1); adder.AddChildNode(4); Assert.Test(root.Leafs == 2); adder.AddChildNode(5); Assert.Test(root.Leafs == 2); }
public void TestHeight() { var root = new Node(3); var adder = new SortTreeChildNodeAdder(root); Assert.Test(root.Height == 1); adder.AddChildNode(2); Assert.Test(root.Height == 2); adder.AddChildNode(4); Assert.Test(root.Height == 2); adder.AddChildNode(5); Assert.Test(root.Height == 3); }
protected Node MakeBinarySortTree(int[] seq) { if (seq.Length < 1) { return(null); } var root = new Node(seq[0]); var adder = new SortTreeChildNodeAdder(root); for (var i = 1; i < seq.Length; i++) { adder.AddChildNode(seq[i]); } return(root); }
public void TestSortTreeChildNodeAdder() { var root = new Node(4); var adder = new SortTreeChildNodeAdder(root); adder.AddChildNode(5); Assert.Test(root.Right.Data == 5); adder.AddChildNode(3); Assert.Test(root.Left.Data == 3); adder.AddChildNode(2); Assert.Test(root.Left.Left.Data == 2); adder.AddChildNode(6); Assert.Test(root.Right.Right.Data == 6); adder.AddChildNode(4); Assert.Test(root.Left.Right.Data == 4); }
public void TestInOrderTraversalIterator() { var root = new Node(5); var adder = new SortTreeChildNodeAdder(root); adder.AddChildNode(4) .AddChildNode(6) .AddChildNode(3) .AddChildNode(7); Node previous = null; foreach (Node n in new InOrderTraversalIterator(root)) { if (previous != null) { Assert.Test(previous.Data <= n.Data); } previous = n; } }
protected Node MakeBinarySortTree(int[] seq) { if (seq.Length < 1) { return null; } var root = new Node(seq[0]); var adder = new SortTreeChildNodeAdder(root); for (var i = 1; i < seq.Length; i++) { adder.AddChildNode(seq[i]); } return root; }
public void TestSortTreeChildNodeAdder() { var root = new Node(4); var adder = new SortTreeChildNodeAdder(root); adder.AddChildNode(5); Assert.Test(root.Right.Data == 5); adder.AddChildNode(3); Assert.Test(root.Left.Data == 3); adder.AddChildNode(2); Assert.Test(root.Left.Left.Data == 2); adder.AddChildNode(6); Assert.Test(root.Right.Right.Data == 6); adder.AddChildNode(4); Assert.Test(root.Left.Right.Data == 4); }
public void TestLeafs() { var root = new Node(3); var adder = new SortTreeChildNodeAdder(root); Assert.Test(root.Leafs == 1); adder.AddChildNode(2); Assert.Test(root.Leafs == 1); adder.AddChildNode(4); Assert.Test(root.Leafs == 2); adder.AddChildNode(5); Assert.Test(root.Leafs == 2); }
public void TestHeight() { var root = new Node(3); var adder = new SortTreeChildNodeAdder(root); Assert.Test(root.Height == 1); adder.AddChildNode(2); Assert.Test(root.Height == 2); adder.AddChildNode(4); Assert.Test(root.Height == 2); adder.AddChildNode(5); Assert.Test(root.Height == 3); }
public void TestInOrderTraversalIterator() { var root = new Node(5); var adder = new SortTreeChildNodeAdder(root); adder.AddChildNode(4) .AddChildNode(6) .AddChildNode(3) .AddChildNode(7); Node previous = null; foreach (Node n in new InOrderTraversalIterator(root)) { if (previous != null) { Assert.Test(previous.Data <= n.Data); } previous = n; } }