예제 #1
0
        public int[] MergeSort_Recursive(int[] arr, int left, int right)
        {
            int mid;

            if (right > left)
            {
                mid = (right + left) / 2;

                MergeSort_Recursive(arr, left, mid);
                Console.WriteLine("Right: " + right.ToString());
                Console.WriteLine("Left: " + left.ToString());
                PrintArray.printArray(arr);
                Console.WriteLine("Next Call");

                MergeSort_Recursive(arr, (mid + 1), right);
                Console.WriteLine("Right: " + right.ToString());
                Console.WriteLine("Left: " + left.ToString());
                PrintArray.printArray(arr);
                Console.WriteLine("Next Call");

                return(DoMerge(arr, left, (mid + 1), right));
            }
            else
            {
                return(arr);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            int[,] matrixA = new int[2, 2] {
                { 1, 2 }, { 3, 4 }
            };
            int[,] matrixB = new int[2, 2] {
                { 5, 6 }, { 7, 8 }
            };
            int[,] matrixC = new int[4, 2] {
                { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }
            };
            int[,] matrixD = new int[2, 3] {
                { 1, 2, 4 }, { 3, 4, 5 }
            };

            Matrix _matrix = new Matrix();

            Console.WriteLine("Multiplication:");
            PrintArray.printMatrix(_matrix.mult(matrixA, matrixB));

            Console.WriteLine("Transpose:");
            PrintArray.printMatrix(_matrix.transpose(matrixC));

            Console.WriteLine("Sum:");
            PrintArray.printMatrix(_matrix.sum(matrixA, matrixB));

            Console.WriteLine("Determinant:");
            Console.WriteLine(_matrix.determinant(matrixA));

            Console.ReadLine();
        }
예제 #3
0
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World! Here's my array: ");

        PrintArray print1 = new PrintArray();

        int[] intArray = new int[5] {
            3, 4, 7, 9, 22
        };
    }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World! Here's my array: ");
			
            PrintArray print1 = new PrintArray();
            int[] intArray = new int[5] { 3, 4, 7, 9, 22 };
			print1.PrintArrayInOrder(intArray);
            print1.PrintArrayInReverse(intArray);
            print1.PrintEvenNumbers(intArray);
            print1.PrintOddNumbers(intArray);
            int[] duplicateFromSomewhere = print1.GetDup(intArray);
            int[] evenNumberArray = print1.ReturnEvenNumbers(intArray);
            print1.ReturnOddNumbers(intArray);
		}
예제 #5
0
        static void Main(String[] args)
        {
            // Setup the board and problem with a 2d array
            var inputPath = Console.ReadLine();
            var sudoku    = CsvToSudoku.CsvImporter(inputPath);

            // Solve the problem
            SudokuSolver.solver(sudoku);
            // Display the result
            if (SudokuSolver.solver(sudoku) == true)
            {
                PrintArray.Print2DArray(sudoku);
            }
            else
            {
                Console.WriteLine("This puzzle is not solvable");
            }
        }
예제 #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to ----------GENERIC PROBLEMS-----------------");

            //Creating and Assigning Values to array
            int[]    intArray    = { 10, 20, 30, 50 };
            double[] doubleArray = { 10.10, 20.20, 30.30 };
            char[]   charArray   = { 'H', 'E', 'L', 'L', 'O' };

            PrintArray <int> generic1 = new PrintArray <int>(intArray); //creating an Object

            generic1.PrintValues();                                     //Calling a method using an Object
            PrintArray <double> generic2 = new PrintArray <double>(doubleArray);

            generic2.PrintValues();
            PrintArray <char> generic3 = new PrintArray <char>(charArray);

            generic3.PrintValues();
            Console.ReadLine();
        }
예제 #7
0
        /*Merge sort is a sorting technique based on divide and conquer technique.
         * With worst-case time complexity being Ο(n log n), it is one of the most respected algorithms.
         * Merge sort first divides the array into equal halves and then combines them in a sorted manner.
         */

        /*Step 1 − if it is only one element in the list it is already sorted, return.
         * Step 2 − divide the list recursively into two halves until it can no more be divided.
         * Step 3 − merge the smaller lists into new list in sorted order.
         */

        private static int[] DoMerge(int[] arr, int left, int mid, int right)
        {
            PrintArray.printArray(arr);
            Console.WriteLine("left: {0} - mid: {1} - rigth: {2}", left, mid, right);
            int[] temp = new int[25];
            int   i, left_end, num_elements, tmp_pos;

            left_end     = (mid - 1);
            tmp_pos      = left;
            num_elements = (right - left + 1);

            while ((left <= left_end) && (mid <= right))
            {
                if (arr[left] <= arr[mid])
                {
                    temp[tmp_pos++] = arr[left++];
                }
                else
                {
                    temp[tmp_pos++] = arr[mid++];
                }
            }

            while (left <= left_end)
            {
                temp[tmp_pos++] = arr[left++];
            }

            while (mid <= right)
            {
                temp[tmp_pos++] = arr[mid++];
            }

            for (i = 0; i < num_elements; i++)
            {
                arr[right] = temp[right];
                right--;
            }
            return(arr);
        }
예제 #8
0
        private static void Main(string[] args)
        {
            //int[] input = new int[13] { 3, 2, 1, 4, 6, 10, 12, 5, 8, 11, 13, 7, 9 };
            //int[] input2 = new int[7] { 45, 22, 37, 28, 55, 16, 38 };
            int[] input3 = new int[8] {
                2, 3, 4, 5, 6, 7, 10, 12
            };

            QuickSort_First.QuickSort(input3, 0, input3.Length - 1);
            PrintArray.Print(input3);
            Console.ReadKey();

            //Quick_Sort_Pivot_Mid.QuickSortDecrease(ref input4, 0, input4.Length-1);
            //Heap_Sort.HeapSort(ref input);
            //input = Radix_Sort.RadixSort(input);
            //PrintArray.Print(input);
            //
            //
            TreeAA treeAA = new TreeAA();

            for (int i = 0; i < 13; i++)
            {
                // treeAA.Insert(input[i]);
            }
            treeAA.Delete(1);
            Console.WriteLine(treeAA.root.right.left.data);
            ///Console.WriteLine(treeAA.Search(100));
            //treeAA.Delete(100);
            // Console.WriteLine(treeAA.Search(100));
            // Console.WriteLine(treeAA.root.right.right.right.data);

            // PrintArray.PrintTest(input4);



            //Linear_Exhaustive.LinearExhaustive(input2, 28);
            // StackCus StackDemo = new StackCus(10);
            //  StackDemo.Push("a");
            // StackDemo.Push("b");
            //StackDemo.Pop();
            // string peek = StackDemo.Peek();
            // bool isEmpty = StackDemo.IsEmpty();
            // Console.WriteLine(StackDemo.top);
            // Console.WriteLine(peek);
            // BTSTree treeDemo = new BTSTree(input[0]);
            // for (int i =1; i< input.Length; i++)
            // {
            //   treeDemo.InsertNodeIndex(input[i], i);
            // }

            // Console.WriteLine("text : {0}", treeDemo.NextSibling(4).data);

            // int ind = treeDemo.Search(15);
            // Console.WriteLine("Position in Array : {0}", ind);
            Console.ReadLine();



            BTSTree newTree = new BTSTree(5);

            newTree.InsertNode(10);
            newTree.InsertNode(3);
            newTree.InsertNode(2);
            newTree.InsertNode(4);
            newTree.InsertNode(6);
            newTree.InsertNode(7);
            newTree.InsertNode(12);
            int index = newTree.Search(16);

            Console.WriteLine(index);
            ;
            // Implement_Queue_Linked_List<int> queueLL = new Implement_Queue_Linked_List<int>();
            // queueLL.Push(15);
            //// queueLL.Push(25);
            //queueLL.Push(30);
            // queueLL.Push(55);

            // Console.WriteLine("head1: {0}",queueLL.headQueue.next.data);
            // Console.WriteLine("tail1: {0}", queueLL.Length);
            //  Console.WriteLine("peek: {0}",queueLL.Peek().data);

            //   Console.WriteLine("Pop: {0}",queueLL.Pop().data);
            // Console.WriteLine("head2: {0}", queueLL.headQueue.data);
            // Console.ReadLine();
            //---check function CountingSort
            // input = Counting_Sort.CountingSort(input);
            //--Check function QuickSort
            // input = Quick_Sort.QuickSort(input);
            // input = Insertion_Sort.InsertionSort(input);
            // input = Shell_Sort.ShellSort(input);
            // int indexSearch = BinarySearch.BinarySearchRecursive(input, 0, 9, 4);
            // Console.WriteLine(indexSearch);
            //  for (int i = 0; i< input.Length; i++)
            // {
            // Console.WriteLine(input[i]);
            // }
            Console.ReadLine();
        }
예제 #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("/*-----------------------*/");

            Console.WriteLine("Chose one:");
            Console.WriteLine("1  - bubble sort");
            Console.WriteLine("2  - insert sort");
            Console.WriteLine("3  - select sort");
            Console.WriteLine("4  - merge sort");
            Console.WriteLine("5  -  sort");
            var opt = Console.ReadLine();

            switch (opt)
            {
            case "1":
                BubbleSort _bs = new BubbleSort();

                int[] arr1 = ArrayGenerator.array1D();
                int[] arr2 = ArrayGenerator.array1D();

                //bs.bubbleSort_rec(arrrec, arrrec.Length)
                Console.WriteLine(@"BUBBLE SORT");
                Console.WriteLine(@"Sorted array by for loop");
                PrintArray.printArray(arr1);
                PrintArray.printArray(_bs.bubbleSort(arr1));
                Console.WriteLine(@"/*-----------------------*/");
                Console.WriteLine(@"Sorted array by recursive method");
                PrintArray.printArray(arr2);
                PrintArray.printArray(_bs.bubbleSort_rec(arr2, arr2.Length));
                Console.WriteLine(@"/*-----------------------*/");
                break;

            case "2":
                InsertSort _is = new InsertSort();

                Console.WriteLine(@"INSERT SORT");
                int[] arr3 = ArrayGenerator.array1D();
                int[] arr4 = ArrayGenerator.array1D();

                Console.WriteLine(@"Sorted array by for\while loop");
                PrintArray.printArray(arr3);
                PrintArray.printArray(_is.insertSort(arr3));
                Console.WriteLine(@"/*-----------------------*/");
                Console.WriteLine(@"Sorted array by recursive method");
                PrintArray.printArray(arr4);
                PrintArray.printArray(_is.insertSort_rec(arr4, arr4.Length));
                Console.WriteLine(@"/*-----------------------*/");
                break;

            case "3":
                SelectionSort _ss = new SelectionSort();
                Console.WriteLine(@"SELECTION SORT");
                int[] arr5 = ArrayGenerator.array1D();

                Console.WriteLine(@"Sorted array by for loop");
                PrintArray.printArray(arr5);
                PrintArray.printArray(_ss.selectionSort(arr5));
                Console.WriteLine(@"/*-----------------------*/");
                break;

            case "4":
                MergeSort _ms = new MergeSort();
                Console.WriteLine(@"SELECTION SORT");
                int[] arr6 = ArrayGenerator.array1D();

                Console.WriteLine(@"Sorted array by for loop");
                PrintArray.printArray(arr6);
                PrintArray.printArray(_ms.MergeSort_Recursive(arr6, 0, arr6.Length - 1));
                Console.WriteLine(@"/*-----------------------*/");
                break;
            }

            Console.ReadKey();
        }