コード例 #1
0
        static void PreviousTests()
        {
            Fibonacci fibonacci = new Fibonacci(9);

            System.Console.WriteLine($"Fib 9 is :{Fibonacci.Fib(9)}");
            System.Console.WriteLine($"Fib 9 is :{fibonacci.ComputeFib()}");
            SimpleQueueGeneric <string> simpleQueue = new SimpleQueueGeneric <string>(2, 2);

            simpleQueue.Enqueue("item1");
            simpleQueue.Enqueue("item2");
            simpleQueue.Enqueue("item3");
            simpleQueue.Enqueue("item4");
            simpleQueue.Enqueue("item5");
            simpleQueue.Enqueue("item6");
            simpleQueue.PrintQueue();
            var item = simpleQueue.Dequeue();

            System.Console.WriteLine($"Dequeued item is: {item}");
            SingleLinkedListCustom <int> single = new SingleLinkedListCustom <int>();

            single.InsertDefault(20);
            single.InsertBegining(25);
            single.PrintLinkedList();
            var           heapTestArray = new int[] { 4, 9, 1, 7, 5, 3 };
            MaxHeap <int> heap          = new CustomHeap.MaxHeap <int>(heapTestArray);

            System.Console.WriteLine($"The Max Heap is:");
            heap.PrintHeap();
            heap.DeleteItem(0);
            heap.PrintHeap();
            MinHeap <int> minHeap = new MinHeap <int>(heapTestArray);

            System.Console.WriteLine($"The Min Heap is:");
            minHeap.PrintHeap();
            minHeap.DeleteItem(0);
            minHeap.PrintHeap();

            var sortedAscending = HeapSortCustom <int> .SortAscending(heapTestArray);

            var sortDesc = HeapSortCustom <int> .SortDescending(heapTestArray);

            var sortedAscendingFromSpan = HeapSortCustom <int> .SortAscending(heapTestArray.AsSpan());

            var sortDescFromSpan = HeapSortCustom <int> .SortDescending(heapTestArray.AsSpan());

            var sortedName = HeapSortCustom <char> .SortDescending("aanderson");
        }
コード例 #2
0
        public void TestInsertDelete()
        {
            SingleLinkedListCustom <int> single = new SingleLinkedListCustom <int>();

            single.InsertDefault(20);
            single.InsertBegining(25);
            single.InsertBegining(5);
            single.InsertDefault(2);
            single.InsertBegining(250);
            var valueAt = single.GetValueAt(1);

            Assert.AreEqual(250, valueAt.Data);
            single.DeletePosition(1);
            single.DeletePosition(1);
            single.DeletePosition(1);
            valueAt = single.GetValueAt(2);
            Assert.AreEqual(2, valueAt.Data);
            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                valueAt = single.GetValueAt(-22);
            });
        }