protected static int[] Merge(int[] left, int[] right)
        {
            int leftIndex = 0, rightIndex = 0;

            //int k=0;
            int[] sorted = new int[left.Length + right.Length];

            for (int k = 0; k < sorted.Length; k++)
            {
                if (leftIndex == left.Length)
                {
                    sorted[k] = right[rightIndex];
                    rightIndex++;
                }
                else if (rightIndex == right.Length)
                {
                    sorted[k] = left[leftIndex];
                    leftIndex++;
                }
                else if (left[leftIndex] < right[rightIndex])
                {
                    sorted[k] = left[leftIndex];
                    leftIndex++;
                }

                else
                {
                    sorted[k] = right[rightIndex];
                    rightIndex++;
                }
            }

            GraphQuestions.DisplayCells(left);
            GraphQuestions.DisplayCells(right);
            GraphQuestions.DisplayCells(sorted);
            Console.WriteLine(".....");
            return(sorted);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            // int[,] trust = { { 1, 3 }, { 2, 3 } };
            //int[][] trust = { new int[] { 1, 3 }, new int[] { 2,6} };
            //int[][] trust = { new int[] { 1,3}, new int[] { 2,3}, new int[] { 3,1}};
            //Console.WriteLine(GraphQuestions.FindJudge(3,trust));

            //int[][] trust2 = { new int[]  { 1, 2 } };
            //Console.WriteLine(GraphQuestions.FindJudge(2, trust2));

            int[][] trust3 = { new int[] { } };
            //Console.WriteLine(GraphQuestions.FindJudge(1, trust3));
            // int[][] jaggedArray = new int[2][];
            // Console.WriteLine(jaggedArray.Length);
            // Console.WriteLine(jaggedArray.GetLength(0));


            // jaggedArray[0][0] = 33;
            //jaggedArray[0][1] = 44;
            //jaggedArray[1][0] = 33;
            //jaggedArray[1][1] = 44;
            //jaggedArray[2][0] = 33;
            //jaggedArray[2][1] = 44;
            //jaggedArray[0] = new int[1] { 20 };
            //jaggedArray[1] = new int[3] { 11, 22, 33 };

            // Console.WriteLine(jaggedArray[0].GetLength(0));
            // Console.WriteLine(jaggedArray[1].GetLength(0));
            // Console.WriteLine(jaggedArray[0].GetLength(1));
            //Console.WriteLine(jaggedArray[1].GetLength(1));
            // LinkedList<Tuple<int, int>> diff = new LinkedList<Tuple<int, int>>();

            int[] arr = { 0, -1, -2, 2, 1 };
            //int k = 1;
            // Console.WriteLine(GraphQuestions.FindPairsWithGivenDifference(arr, k));
            int[] arr1 = { 1, 3, 1, 5, 4 };
            int   k    = 0;

            //Console.WriteLine(GraphQuestions.FindPairs(arr1, k));
            //int numCourses = 3;
            //int[][] prerequisites = {new int[]{1, 0},new int[]{0, 2} };

            //int numCourses = 3;
            //int[][] prerequisites = { new int[] { 1, 0 }, new int[] { 0,2 } };

            //int numCourses = 4;
            //int[][] prerequisites = { new int[] { 2, 0 }, new int[] { 1, 0 }, new int[] { 3, 1 }, new int[] { 3, 2 }, new int[] { 1, 3 } };


            // Console.WriteLine(GraphQuestions.CanFinish(numCourses, prerequisites));
            //GraphQuestions.PrintLinkedList();

            int[] cells = { 0, 1, 0, 1, 1, 0, 0, 1 };
            int   N     = 16;

            //int[] cells = { 0, 1, 0};
            //int N = 4;
            // { 2, 100, 50, 120, 1000]

            //GraphQuestions.DisplayCells(GraphQuestions.PrisonAfterNDays(cells, N));
            //string b = "()()))";
            //Console.WriteLine(GraphQuestions.bracketMatch(b));

            ////double[] grants ={2, 100, 50, 120, 1000};
            ////double bud = 190;
            //double bud = 40;

            //double[] grants ={10, 5, 20, 30 };

            //Console.WriteLine(GraphQuestions.FindGrantsCap(grants,bud));
            //int[] array1 = { 99,44,6,2,1,5,63,87,283,4,0 };
            //int[] array1 = { 99, 44, 6, 2, 1};
            //GraphQuestions.DisplayCells(SortingAlgorithms.MergeSort(array1));

            //    string[] logs = { "a1 9 2 3 1", "g1 act car", "zo4 4 7", "ab1 off key dog", "a8 act zoo", "a2 act car" };
            //    ["let1 art can test", "let1 art can"]
            //GraphQuestions.DisplayCells(GraphQuestions.ReorderLogFiles(logs));
            //    string[][] head = { { 7, null }, { 13, 0 }, { 11, 4 },[10, 2],[1, 0]]

            //    Console.WriteLine(LeetCodeLockDownChallenge.IsHappy(2));
            //    Console.WriteLine(StringArray.LengthOfLongestSubstring("pwwkew"));

            //int[] array = { 10, 3, 2, 7, 7, 5, 8, 4, 1, 2, 9, 7, 8, 11 };
            //GraphQuestions.DisplayCells(array);
            //array = QuickSortAlgo.QuickSort(array, 0, array.Length-1);
            //GraphQuestions.DisplayCells(array);

            //int[] array2 = { 2, 1, 5 ,3 ,4 };
            //int[] array2 = { 5, 1, 5, 3, 2 };
            int[] array2 = { 2, 5, 1, 3, 4 };
            GraphQuestions.DisplayCells(array2);
            string s = BubbleSortAlgo.BubbleSort(array2);

            Console.WriteLine(s);
            // GraphQuestions.DisplayCells(array2);

            Console.ReadKey();
        }