Beispiel #1
0
        public static void smartBubbleSort()
        {
            int size1 = 10;

            Console.WriteLine();
            Console.WriteLine("**************************************!");
            Console.WriteLine("Below is the Smart bubble sort~!");
            Console.WriteLine("Unsorted Array");
            randomIntArray = new int[size1];

            Random rnd = new Random();

            for (int i = 0; i < size1; i++)
            {
                randomIntArray[i] = rnd.Next(size1 * 2);
                Console.Write(randomIntArray[i] + " ");
            }

            var timeUnit = Timing.TimeUnit.Miliseconds;

            Timing.Result <Timing.NoReturn> smartResult = null;

            Console.WriteLine();
            Console.WriteLine();
            smartResult = Timing.GetTime(() => SmartBubbleSort.SmartBubbleSortArrayList <int>(randomIntArray), timeUnit);

            Console.WriteLine("Time to sort: " + smartResult.Time.ToString() + " miliseconds");

            Console.WriteLine();
            Console.WriteLine("Sorted Array: ");
            for (int i = 0; i < randomIntArray.Length; i++)
            {
                Console.Write(randomIntArray[i] + " ");
            }
        }
Beispiel #2
0
        public static void convertNumbersToLetters()
        {
            int intsize = 25;

            Console.WriteLine();
            Console.WriteLine("**************************************!");
            Console.WriteLine("Below is the Letter sort~!");
            Console.WriteLine("Unsorted Letters");
            randomIntArray1 = new int[intsize];

            Random rnd10 = new Random();

            for (int i = 0; i < intsize; i++)
            {
                randomIntArray1[i] = rnd10.Next(intsize);
                //Console.Write(randomIntArray1[i] + " ");
            }
            Console.WriteLine();
            //iterate through the array
            for (int i = 0; i < randomIntArray1.Length; i++)
            {
                //convert the number values into letters
                char let = (char)('a' + randomIntArray1[i]);
                Console.Write(let + " ");
            }

            //calculate time to carry out request
            var timeUnit = Timing.TimeUnit.Miliseconds;

            Timing.Result <Timing.NoReturn> result10 = null;

            Console.WriteLine();
            Console.WriteLine();
            result10 = Timing.GetTime(() => BubbleSort.BubbleSortArrayList <int>(randomIntArray1), timeUnit);

            Console.WriteLine("Time to sort letters: " + result10.Time.ToString() + " miliseconds");

            Console.WriteLine();
            Console.WriteLine("Sorted Letters: ");
            for (int i = 0; i < randomIntArray1.Length; i++)
            {
                //Console.Write(randomIntArray1[i] + " ");
            }
            Console.WriteLine();
            for (int i = 0; i < randomIntArray1.Length; i++)
            {
                char let = (char)('a' + randomIntArray1[i]);
                Console.Write(let + " ");
            }
        }
Beispiel #3
0
        public static void insertionSort()
        {
            int size1 = 10;

            Console.WriteLine();
            Console.WriteLine("**************************************!");
            Console.WriteLine("Below is the Insertion Sort~!");
            Console.WriteLine("Unsorted Array");
            randomIntArray = new int[size1];

            Random rnd = new Random();

            //iterate through array
            for (int i = 0; i < size1; i++)
            {
                //multiply the random number by 2 to get more variety
                randomIntArray[i] = rnd.Next(size1 * 2);
                Console.Write(randomIntArray[i] + " ");
            }

            //calculate time to carry out request
            var timeUnit = Timing.TimeUnit.Miliseconds;

            Timing.Result <Timing.NoReturn> insertionResult = null;

            //create space
            Console.WriteLine();
            Console.WriteLine();

            insertionResult = Timing.GetTime(() => InsertionSort.InsertionSortArrayList <int>(randomIntArray), timeUnit);

            Console.WriteLine("Time to sort: " + insertionResult.Time.ToString() + " miliseconds");

            Console.WriteLine();
            Console.WriteLine("Sorted Array: ");
            //iterate through sorted array
            for (int i = 0; i < randomIntArray.Length; i++)
            {
                //show the sorted array
                Console.Write(randomIntArray[i] + " ");
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //Sort Section

            insertionSort();
            Console.WriteLine();
            Console.WriteLine();
            reverseSort();
            Console.WriteLine();
            Console.WriteLine();
            bubbleSort();
            Console.WriteLine();
            Console.WriteLine();
            smartBubbleSort();
            Console.WriteLine();
            Console.WriteLine();
            convertNumbersToLetters();
            Console.WriteLine();
            Console.WriteLine();



            //insertion into Arraylist and time comparison
            Console.WriteLine();
            var timeUnit2 = Timing.TimeUnit.Miliseconds;

            //calculate time to carry out request
            Timing.Result <Timing.NoReturn> result2 = null;

            result2 = Timing.GetTime(() => addToArray(), timeUnit2);

            Console.WriteLine();
            Console.WriteLine("Time to add " + getSize() + " numbers: " + result2.Time.ToString() + " miliseconds");

            //Adding into a Collection and time comparison
            Console.WriteLine();
            //calculate time to carry out request
            var timeUnit3 = Timing.TimeUnit.Miliseconds;

            Timing.Result <Timing.NoReturn> result3 = null;

            result3 = Timing.GetTime(() => addToCollection(), timeUnit3);

            Console.WriteLine();
            Console.WriteLine("Time to add " + collection.Count() + " numbers: " + result3.Time.ToString() + " miliseconds");

            Console.WriteLine();

            getStack();


            // Binary Tree
            BinaryTree b = new BinaryTree();

            //insert the values
            b.insert(48);
            b.insert(10);
            b.insert(16);
            b.insert(23);
            b.insert(51);
            b.insert(3);

            //display the values
            b.display();

            //carry out the quadratic hash
            getQHash();


            //bucket hash
            Console.WriteLine("Bucket Hash");
            BucketHash.bucket();
            Console.WriteLine("");
            Console.ReadKey();

            //queue
            Console.WriteLine("Queue");
            queue.queues();
            Console.WriteLine("");

            //iterator
            Console.WriteLine("iterator");
            iteratormethod();

            //circular list
            Console.WriteLine("");
            Console.WriteLine("Circular list");
            circularlist();

            //Circular linked list
            Console.WriteLine("");
            circularlinklit();

            Console.ReadLine();
            Console.ReadKey();
        }