public void TestSort()
        {
            int[] arr = { 2, 7, 3, 11, 6 };

            int[] sortedArr = (int[])arr.Clone();
            Array.Sort(sortedArr);

            int[] mySortedArr = (int[])arr.Clone();
            MySort.InsertionSort(mySortedArr);

            Assert.AreEqual(sortedArr, mySortedArr);
        }
示例#2
0
        static void Main(string[] args)
        {
            // Linked List Example
            LinkedList.LinkedList <int> list = new LinkedList.LinkedList <int>();

            list.push_back(123);
            list.push_back(456);
            list.push_back(789);

            int i = 1;

            foreach (int val in list)
            {
                Console.WriteLine($"{i}: {val}");
                i += 1;
            }

            Console.WriteLine(list);

            list.pop_back();
            Console.WriteLine(list);

            list.pop_back();
            Console.WriteLine(list);

            list.pop_back();
            Console.WriteLine(list);


            // Binary Tree Example
            BinaryTree.BinaryTree <int, int> tree = new BinaryTree.BinaryTree <int, int>();

            tree.insert(2, 123);
            tree.insert(1, 456);
            tree.insert(3, 789);

            tree.remove(2);

            tree.find(2);
            tree.find(1);
            tree.find(3);


            // Insertion Sort Example
            int[] arr = { 2, 7, 3, 11, 6 };

            MySort.InsertionSort(arr);
        }
        static void Main(string[] args)
        {
            var csvReader = new CSVreader();
            var mySearch  = new MySearch(); //Linear and Binary, Binary should only sort sorted data
            var mySort    = new MySort();   //Insert and Shell

            string path = "C:/Users/New/Documents/visual studio 2017/Projects/Algorithms1Console/unsorted_numbers.csv";

            int[] data = csvReader.ReadFile(path); // comment out unnecessary stuff

            int[] sorted = mySort.InsertionSort(data);

            Console.WriteLine("Linear Search");
            var linearstopwatch = Stopwatch.StartNew();

            mySearch.LinearSearchHighest(data);
            linearstopwatch.Stop();
            Console.WriteLine("Linear Search: " + ((linearstopwatch.Elapsed.TotalMilliseconds).ToString()));

            Console.WriteLine();

            //Console.WriteLine("Binary Search");
            //var binarystopwatch = Stopwatch.StartNew();
            //mySearch.LinearSearchHighest(data);
            //binarystopwatch.Stop();
            //Console.WriteLine("Binary Search: " + ((binarystopwatch.Elapsed.TotalMilliseconds).ToString()));

            //Console.WriteLine();

            Console.WriteLine("Linear 1500th Search");
            var linear1500thstopwatch = Stopwatch.StartNew();

            mySearch.LinearSearchEvery1500th(sorted);
            linear1500thstopwatch.Stop();
            Console.WriteLine("Linear 1500th Search: " + ((linear1500thstopwatch.Elapsed.TotalMilliseconds).ToString()));

            Console.WriteLine();

            //Console.WriteLine("Binary 1500th Search");
            //var binary1500thstopwatch = Stopwatch.StartNew();
            //mySearch.BinarySearchEvery1500th(sorted);
            //binary1500thstopwatch.Stop();
            //Console.WriteLine("Binary 1500th Search: " + ((binary1500thstopwatch.Elapsed.TotalMilliseconds).ToString()));

            Console.ReadKey();
        }