public void ListToTree(int[] values) { ImmutableAVL tree = new ImmutableAVL(values); Assert.AreEqual(values.Length, tree.Count()); Assert.IsTrue(isAVLTreeValid(tree)); }
public override Tuple <double, double> RunDeletion(int arraySize, int nbArrays) { Init(arraySize, nbArrays); Stopwatch watch; double elapsedMsMutable = 0; double elapsedMsImmutable = 0; for (int i = 0; i < nbArrays; i++) { AVL tree = new AVL(arrays[i]); tree.Add(0); watch = Stopwatch.StartNew(); tree.Delete(0); watch.Stop(); double ticks = watch.ElapsedTicks; double microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsMutable += microseconds; ImmutableAVL immutableAvl = new ImmutableAVL(arrays[i]); immutableAvl.Add(0); watch = Stopwatch.StartNew(); immutableAvl.Delete(0); watch.Stop(); ticks = watch.ElapsedTicks; microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsImmutable += microseconds; } elapsedMsMutable /= nbArrays; elapsedMsImmutable /= nbArrays; return(new Tuple <double, double>(elapsedMsMutable, elapsedMsImmutable)); }
public void Peek(int[] values) { ImmutableAVL tree = new ImmutableAVL(values); int peek = tree.Peek(); Assert.AreEqual(peek, values.Min()); Assert.AreEqual(values.Length, tree.Count()); }
public void Insert(int[] values) { ImmutableAVL tree = new ImmutableAVL(values); tree.Add(5); Assert.AreEqual(values.Length + 1, tree.Count()); Assert.IsTrue(isAVLTreeValid(tree)); }
public void Pop(int[] values) { ImmutableAVL tree = new ImmutableAVL(values); int pop = tree.Pop(); Assert.AreEqual(pop, values.Min()); Assert.AreEqual(values.Length - 1, tree.Count()); Assert.IsTrue(isAVLTreeValid(tree)); }
private void dichotomyTree(ImmutableAVL tree, int[] array, int start, int end) { double middle = (end - start) / 2; int rootIndex = (int)Math.Floor(middle); tree.root = tree.Add(array[start + rootIndex]); if (end - start > 0) { if (start + rootIndex - 1 >= 0) { dichotomyTree(tree, array, start, start + rootIndex - 1); } if (start + rootIndex + 1 >= 0 && end >= 0) { dichotomyTree(tree, array, start + rootIndex + 1, end); } } }
private bool isAVLTreeValid(ImmutableAVL tree) { return(recursiveCheck(tree.Head())); }