Esempio n. 1
0
        static void Main(string[] args)
        {
            Something[] userArray = new Something[5];
            userArray[0] = new Something {
                Name = "Car"
            };
            userArray[1] = new Something {
                Name = "Moto"
            };
            userArray[2] = new Something {
                Name = "Bike"
            };
            userArray[3] = new Something {
                Name = "Tram"
            };
            userArray[4] = new Something {
                Name = "Bas"
            };

            int[] test = new int[] { 10, 5, -12, 0, 16 };

            BubbleSorter <Something> bubble = new BubbleSorter <Something>(userArray.Clone() as Something[]);

            bubble.Print();
            bubble.Sort();
            bubble.Print();

            InsertionSorter <Something> insrt = new InsertionSorter <Something>(userArray.Clone() as Something[]);

            insrt.Print();
            insrt.Sort();
            insrt.Print();

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int arraySize = 10;

            int[]  array = new int[arraySize]; // creating array
            Random rnd   = new Random();

            Console.Write("Initial array - ");
            for (int i = 0; i < arraySize; i++) // filling aray with random values
            {
                array[i] = rnd.Next(100);
            }

            BubbleSorter    bubbleSortingArray = new BubbleSorter(array);
            InsertionSorter insertSortingArray = new InsertionSorter(array);

            bubbleSortingArray.Print();

            char pressed = '0';

            Console.WriteLine("How do you want to sort this array?");
            Console.WriteLine("b - Bubble sorting");
            Console.WriteLine("i - Insertion sorting");

            while (pressed != 'b' && pressed != 'i') //checking for correct char
            {
                pressed = Convert.ToChar(Console.ReadLine());
                switch (pressed)
                {
                case 'b':
                    bubbleSortingArray.Sort();
                    Console.Write("Bubble sorted array - ");
                    bubbleSortingArray.Print();
                    break;

                case 'i':
                    insertSortingArray.Sort();
                    Console.Write("Insertion sorted array - ");
                    insertSortingArray.Print();
                    break;

                default:
                    Console.WriteLine("Please press <b> or <i>");
                    break;
                }
            }

            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            int[]        UserArray  = new int[] { 9, -9, 100, 0, -99, 50, 12, -18, 10, 5 };
            BubbleSorter bubbleMtrx = new BubbleSorter((int[])UserArray.Clone());

            bubbleMtrx.Print();
            bubbleMtrx.Sort();
            bubbleMtrx.Print();
            InsertionSorter insertionMtrx = new InsertionSorter((int[])UserArray.Clone());

            insertionMtrx.Print();
            insertionMtrx.Sort();
            insertionMtrx.Print();
            Console.ReadKey();
        }