public void ExampleTest() { AvlNode[] tree = { new AvlNode(3) { Lch = -1, Rch = 1 }, new AvlNode(4) { Lch = -1, Rch = -1 } }; _avl.BuildTree(tree); _avl.Insert(5); var result = _avl.Reorder(); result.ShouldContain(new AvlNode(4) { Lch = 2, Rch = 3 }, new AvlNode(3) { Lch = 0, Rch = 0 }, new AvlNode(5) { Lch = 0, Rch = 0 }); }
public override void Execute() { var length = ReadInt(); var tree = new AvlNode[length]; for (int i = 0; i < length; i++) { var numbers = ReadIntArray(); tree[i] = new AvlNode(numbers[0]) { Lch = numbers[1] - 1, Rch = numbers[2] - 1 }; } _avl.BuildTree(tree); _avl.Rotation(); var result = _avl.Reorder(); WriteLine(result.Count); foreach (var node in result) { WriteLine($"{node.Value} {node.Lch} {node.Rch}"); } }
public void ExampleTest() { AvlNode[] tree = { new AvlNode(-2) { Lch = 6, Rch = 1 }, new AvlNode(8) { Lch = 3, Rch = 2 }, new AvlNode(9) { Lch = -1, Rch = -1 }, new AvlNode(3) { Lch = 4, Rch = 5 }, new AvlNode(0) { Lch = -1, Rch = -1 }, new AvlNode(6) { Lch = -1, Rch = -1 }, new AvlNode(-7) { Lch = -1, Rch = -1 } }; _avl.BuildTree(tree); _avl.Rotation(); var result = _avl.Reorder(); result.ShouldContain(new AvlNode(3) { Lch = 2, Rch = 3 }, new AvlNode(-2) { Lch = 4, Rch = 5 }, new AvlNode(8) { Lch = 6, Rch = 7 }, new AvlNode(-7) { Lch = 0, Rch = 0 }, new AvlNode(0) { Lch = 0, Rch = 0 }, new AvlNode(6) { Lch = 0, Rch = 0 }, new AvlNode(9) { Lch = 0, Rch = 0 }); }