Exemplo n.º 1
0
        public void SimpleQuickTest()
        {
            int[] xs = { 3, 2, 1, 6, 5, 9, 4 };
            Quick <int> .SimpleSort(xs);

            Assert.True(Sorting <int> .IsSorted(xs));
        }
Exemplo n.º 2
0
        public void MaxPriorityQueueTest()
        {
            int[] xs    = { 3, 2, 1, 6, 5, 9, 4 };
            var   queue = new MaxPriorityQueue <int>(xs.Length);

            for (int i = 0; i < xs.Length; i++)
            {
                queue.Insert(xs[i]);
            }
            Quick <int> .SimpleSort(xs);

            for (int i = xs.Length - 1; i > 0; i--)
            {
                int v = queue.DelMax();
                Assert.Equal(v, xs[i]);
            }
        }
Exemplo n.º 3
0
        public void IndexMinPrivorityQueueTest()
        {
            string[] strings1 = { "it", "was", "the", "best", "of", "times", "it", "was", "the", "worst" };
            string[] strings2 = new string[strings1.Length];
            Array.Copy(strings1, strings2, strings1.Length);
            var queue = new IndexMinPriorityQueue <string>(strings1.Length);

            for (int i = 0; i < strings1.Length; i++)
            {
                queue.Insert(i, strings1[i]);
            }
            Quick <string> .SimpleSort(strings2);

            for (int i = 0; i < strings1.Length; i++)
            {
                int index = queue.DelMin();
                Assert.Equal(strings1[index], strings2[i]);
            }
        }