public void IndicatesWhenNoItemFound(int searchedValue) { var someArray = new[] { 1, 2, 5, 6 }; var itemFound = BinarySearch.BinarySearchRecursive(searchedValue, someArray); var itemFoundIteratively = BinarySearch.BinarySearchIterative(searchedValue, someArray); Assert.False(itemFound); Assert.False(itemFoundIteratively); }
static void Main(string[] args) { int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray(); int x = int.Parse(Console.ReadLine()); int index = BinarySearch.BinarySearchIterative(arr, x, 0, arr.Length - 1); Console.WriteLine(index); }
public void FindsAnItem(int searchedValue) { var someArray = new [] { 1, 2, 3, 4, 5 }; var itemFound = BinarySearch.BinarySearchRecursive(searchedValue, someArray); var itemFoundIteratively = BinarySearch.BinarySearchIterative(searchedValue, someArray); Assert.True(itemFound); Assert.True(itemFoundIteratively); }
static void Main(string[] args) { int[] arr = { 2, 3, 4, 10, 40 }; int key = 10; int?resultIterative = BinarySearch.BinarySearchIterative(arr, key); if (resultIterative == null) { Console.WriteLine("Element not present in BinarySearchIterative"); } else { Console.WriteLine("Element found in BinarySearchIterative at " + "index " + resultIterative); } int min = 0; int max = arr.Length; int?resultRecursive = BinarySearch.BinarySearchRecursive(arr, key, min, max); if (resultRecursive == null) { Console.WriteLine("Element not present in BinarySearchRecursive"); } else { Console.WriteLine("Element found in BinarySearchRecursive at " + "index " + resultRecursive); } int[] numbers = { 3, 8, 7, 5, 2, 1, 9, 6, 4 }; int len = numbers.Length; int[] data = new int[] { -1, 25, -58964, 8547, -119, 0, 78596 }; MergeSortIterative(ref data); Console.WriteLine("MergeSort By Iterative Method Debug needed"); MergeSort.MergeSort_Iterative(numbers, 0, len - 1); for (int i = 0; i < 9; i++) { Console.WriteLine(numbers[i]); } Console.WriteLine("MergeSort By Iterative Method using ref"); for (int i = 0; i < data.Length; i++) { Console.WriteLine(data[i]); } }