public void MergeTwoListsTestCase3() { var list2 = CommonHelpers.GetLinkedListFromArray(new[] { 0 }); var output = MergeTwoSortedLinkedLists.MergeTwoLists(null, list2).ValuesToFlatList(); output.SequenceEqual(new [] { 0 }).Should().BeTrue(); }
public void MergeTwoListsTestCase4() { var list1 = CommonHelpers.GetLinkedListFromArray(new[] { 1, 2, 4, 5, 6, 7 }); var list2 = CommonHelpers.GetLinkedListFromArray(new[] { 1, 3, 4 }); var output = MergeTwoSortedLinkedLists.MergeTwoLists(list1, list2).ValuesToFlatList(); output.SequenceEqual(new[] { 1, 1, 2, 3, 4, 4, 5, 6, 7 }).Should().BeTrue(); }
public void MergeOneItemWithOneItemLists_ShouldReturnTwoSortedItemsList() { var mergedLists = MergeTwoSortedLinkedLists.Merge(new MergeTwoSortedLinkedLists.ListNode(2), new MergeTwoSortedLinkedLists.ListNode(1)); mergedLists.Should().BeEquivalentTo( new MergeTwoSortedLinkedLists.ListNode(1) { next = new MergeTwoSortedLinkedLists.ListNode(2) }); }
public void TestMethod_Pointers(string list1, string list2, string expected) { int[] arr1 = Array.ConvertAll(list1.Split(' '), temp => Convert.ToInt32(temp)); int[] arr2 = Array.ConvertAll(list2.Split(' '), temp => Convert.ToInt32(temp)); SinglyLinkedListNode sln = new SinglyLinkedListNode(); SinglyLinkedListNode head1 = sln.GenerateSinglyLinkedList(arr1); SinglyLinkedListNode head2 = sln.GenerateSinglyLinkedList(arr2); MergeTwoSortedLinkedLists mts = new MergeTwoSortedLinkedLists(); SinglyLinkedListNode merged = mts.MergeListsUsePointers(head1, head2); string result = ""; while (merged != null) { result = result + merged.Data.ToString() + " "; merged = merged.Next; } Assert.AreEqual(result.Trim(), expected); }
public void MergeTwoListsTestCase2() { var output = MergeTwoSortedLinkedLists.MergeTwoLists(null, null); output.Should().BeNull(); }
static void Main(string[] args) { SortedMatrixSearch.Run(); SparseSearch.Run(); SearchInRotatedArray.Run(); GroupAnagrams.Run(); CombinationsOfNPairsParentheses.Run(); PermutationWithDuplicates.Run(); PermutationNoDuplicates.Run(); var subsetList = new List <List <int> >(); subsetList = SubsetInSet.FindAllSubsetInSet(new List <int> { 1, 2, 3 }); ReverseLinkedList.Run(); IsUniqueString.Run(); StoneDivisionProblem.Run(); Kangaroo.Run(); AppleAndOrange.Run(); AbbreviationProblem.Run(); FibonacciModifiedProblem.Run(); RecursiveDigitSum.Run(); RangeSumOfBST.Run(); GradingStudentsProblem.Run(); // XorSequenceProblem.Run(); CounterGameProblem.Run(); MaximizingXORProblem.Run(); LonelyIntegerProblem.Run(); FlippingBitsProblem.Run(); QueueUsingTwoStacksProblem.Run(); GetNodeValue.Run(); MergeTwoSortedLinkedLists.Run(); Compare_Two_linked_lists.Run(); DeleteNodeProblem.Run(); ArrayManipulationProblem.Run(); LeftRotationProblem.Run(); HourGlass2D.Run(); SimpleTextEditorProblem.Run(); EqualStacksProblem.Run(); MaximumElementProblem.Run(); BinarySearchTreeInsertion.Run(); TopViewProblem.Run(); TimeConvertsionProblem.Run(); BinaryTreePathsProblem.Run(); IncreasingOrderSearchTree.Run(); RemoveAllAdjacentDuplicatesInStringWithKLength.Run(); RemoveAllAdjacentDuplicatesInString.Run(); CheckStraightLineProblem.Run(); HouseRobber.Run(); UniquePathsProblem.Run(); FirstUniqueCharacterInString.Run(); BinaryTreeInorderTraversal.Run(); DailyTemperaturesProblem.Run(); CountingBitsproblem.Run(); SortIntegersByTheNumberOf1BitsProblem.Run(); HammingDistanceProblem.Run(); RansomNoteProblem.Run(); ConvertBinaryNumberInLinkedListToIntegerProblem.Run(); NumberOfStepsToReduceNumberToZeroProblem.Run(); JewelsAndStones.Run(); ClimbingStairsProblem.Run(); BestTimeToBuyAndSellStock.Run(); MajorityElementProblem.Run(); MoveZeroesProblem.Run(); InvertBinaryTree.Run(); SingleNumberProblem.Run(); MaximumDepthInTrree.Run(); MergeTwoBinaryTrees.Run(); AddBinaryProblem.Run(); PlusOneProblem.Run(); LengthOfLastWordProblem.Run(); KadaneAlgorithmForMaxSubArray.Run(); KMPAlgorithm.Run(); CountAndSayProblem.Run(); SearchInsertPosition.Run(); ImplementIndexOfString.Run(); RemoveElement.Run(); RemoveDuplicatesFromSortedArray.Run(); MergeTwoSortedLists.Run(); ValidParentheses.Run(); LongestCommonPrefix.Run(); RomanToInteger.Run(); PalindromeNumber.Run(); ReverseInteger.Run(); TwoSumProblem.Run(); AddOneToNumber.Run(); MostAmountOfChange.Run(); #region BinaryTree LeastCommonAncestor.Run(); PrintAllPaths.Run(); HasPathSum.Run(); CheckIfBinaryTreeIsBinarySearchTree.Run(); PrintAllNodesWithRangeInBinarySearchTree.Run(); UniqueTreeStructureNumber.Run(); MirrorTree.Run(); #region BitManuiplation_GetNthNumber NumberOfStepsToReduceNumberToZeroProblem.Run(); CountNumbersOf1InBit.Run(); ReverseThebitsInInteger.Run(); PrintBitsInInteger.Run(); GetNthBit.Run(); setNthBitTo1.Run(); SetNthBitTo0.Run(); #endregion MinimumtValueInTrree minValueInTree = new MinimumtValueInTrree(); minValueInTree.Run(); #endregion #region Recursion Chessboard chessboard = new Chessboard(); chessboard.Run(); RatPathToMaze ratPathToMaze = new RatPathToMaze(); ratPathToMaze.Run(); List <string> anagramList = new List <string>(); anagramList = WordAnagram.GenerateWordAnagram("abc"); Pixel[,] pixelList = new Pixel[3, 3] { { new Pixel(0, 0, "red"), new Pixel(0, 1, "green"), new Pixel(0, 2, "green") }, { new Pixel(1, 0, "red"), new Pixel(1, 1, "green"), new Pixel(1, 2, "green") }, { new Pixel(2, 0, "red"), new Pixel(2, 1, "green"), new Pixel(2, 2, "green") } }; FillPaint.PaintFill(pixelList, 1, 2, "green", "black"); BinaryTreesAreTheSame.Run(); #endregion #region General problems RotateArrayByKSpaces.Run(); #region AddtwoNumbersReferencedByTheirDigits var addRes = AddtwoNumbersReferencedByTheirDigits.AddNumbers(new int[] { 1, 2, 7 }, new int[] { 9, 4 }); #endregion #region RunLengthEncoding var encodedStr = RunLengthEncoding.Encode("aabbbbc"); var decodedStr = RunLengthEncoding.Decode(encodedStr); #endregion #region BreakDocumentIntoChunk var chunkRes = BreakDocumentIntoChunk.Chunkify("ab:dd:ddfcct:aab:cccc", ':', 5); #endregion #region GameOfLife var gameRes = GameOfLife.GetNextInteration(new int[3, 3] { { 1, 0, 0 }, { 0, 1, 1 }, { 1, 0, 0 } }); #endregion . #endregion #region InsertionSort InsertionSort.insertionSort(listToSort); #endregion #region BinarySearch Console.WriteLine(String.Format("%s is present at index: %s", 30, BinarySearch.binarySearch(sortedArray, 30, 0, sortedArray.Length - 1))); Console.WriteLine(String.Format("%s is present at index: %s", 4, BinarySearch.binarySearch(sortedArray, 4, 0, sortedArray.Length - 1))); Console.WriteLine(String.Format("%s is present at index: %s", 15, BinarySearch.binarySearch(sortedArray, 15, 0, sortedArray.Length - 1))); #endregion #region MergeSort MergeSort.print(listToSort); MergeSort.mergeSort(listToSort); #endregion #region QuickSort QuickSort.print(listToSort); QuickSort.quickSort(listToSort, 0, listToSort.Length - 1); QuickSort.print(listToSort); #endregion }
public void MergeNullLists_ShouldReturnNull() { var mergedLists = MergeTwoSortedLinkedLists.Merge(null, null); mergedLists.Should().BeNull(); }
public void MergeList1AndList2_ShouldReturnMergedList1And2() { var mergedLists = MergeTwoSortedLinkedLists.Merge(GetList1(), GetList2()); mergedLists.Should().BeEquivalentTo(GetMergedList1And2()); }
public void MergeNonEmptyAndNullLists_ShouldReturnNonEmptyList() { var mergedLists = MergeTwoSortedLinkedLists.Merge(GetList1(), null); mergedLists.Should().BeEquivalentTo(GetList1()); }
public void MergeNullAndNonEmptyLists_ShouldReturnNonEmptyList() { var mergedLists = MergeTwoSortedLinkedLists.Merge(null, GetList2()); mergedLists.Should().BeEquivalentTo(GetList2()); }