public void InorderTraversalTest1() { TreeNode root = new TreeNode(1); root.left = new TreeNode(2); root.left.left = new TreeNode(4); root.left.right = new TreeNode(5); root.right = new TreeNode(3); root.right.left = new TreeNode(6); root.right.right = new TreeNode(7); IList <int> expected = new List <int>() { 4, 2, 5, 1, 6, 3, 7 }; var result = new BinaryTreeInorderTraversal().InorderTraversal(root); Assert.AreEqual(expected, result); }
public void InorderTraversalSingleNodeTest() { var tree = new MyBinaryTree(1); BinaryTreeInorderTraversal.InorderTraversal(tree).Should().ContainInOrder(new List <int> { 1 }); }
public void InorderTraversalTest3() { TreeNode root = null; IList <int> expected = new List <int>() { }; var result = new BinaryTreeInorderTraversal().InorderTraversal(root); Assert.AreEqual(expected, result); }
public void InorderTraversalOfIeterationTest2() { TreeNode root = new TreeNode(1); IList <int> expected = new List <int>() { 1 }; var result = new BinaryTreeInorderTraversal().InorderTraversalOfIteration(root); Assert.AreEqual(expected, result); }
public void InorderTraversalTestCase2() { var tree = new MyBinaryTree(2); tree.Left = new MyBinaryTree(3); tree.Left.Left = new MyBinaryTree(1); BinaryTreeInorderTraversal.InorderTraversal(tree).Should().ContainInOrder(new List <int> { 1, 3, 2 }); }
public void InorderTraversalTest() { TreeNode root = new TreeNode(1); root.right = new TreeNode(2); root.right.left = new TreeNode(3); IList <int> expected = new List <int>() { 1, 3, 2 }; var result = new BinaryTreeInorderTraversal().InorderTraversal(root); Assert.AreEqual(expected, result); }
public void TestMethod2() { // Arrange BinaryTreeInorderTraversal question = new BinaryTreeInorderTraversal(); TreeNode root = new TreeNode(1); root.right = new TreeNode(2); root.right.left = new TreeNode(3); int[] expected = new int[] { 1, 3, 2 }; // Act IList <int> actual = question.InorderTraversal2(root); // Assert CollectionAssert.AreEqual(expected, actual?.ToArray()); }
public void InorderTraversalTestCase1() { var tree = new MyBinaryTree(6); tree.Left = new MyBinaryTree(2); tree.Left.Left = new MyBinaryTree(1); tree.Left.Right = new MyBinaryTree(4); tree.Left.Right.Left = new MyBinaryTree(3); tree.Left.Right.Right = new MyBinaryTree(5); tree.Right = new MyBinaryTree(7); tree.Right.Right = new MyBinaryTree(9); tree.Right.Right.Left = new MyBinaryTree(8); BinaryTreeInorderTraversal.InorderTraversal(tree).Should().ContainInOrder(new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); }
public void binaryTreeInorderTraversalTest() { var result = BinaryTreeInorderTraversal.InorderTraversal(root); Console.WriteLine("Inorder Traversal: "); foreach (int i in result) { Console.Write(i + ", "); } Console.WriteLine(); var iterativeInorder = BinaryTreeInorderTraversal.IterativeInorderTraversal(root); Console.WriteLine("Inorder Traversal: "); foreach (int i in iterativeInorder) { Console.Write(i + ", "); } }
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 Setup() { solution = new BinaryTreeInorderTraversal(); }