Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
13
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { static int binarySearch(String[] book, String x) { int left = 0, right = book.Length - 1; while (left <= right) { int mid = left + (right - left) / 2; int res = x.CompareTo(book[mid]); if (res == 0) return mid; if (res > 0) left = mid + 1; else right = mid - 1; } return -1;} public static void Main(String []args) { String[] book = {"Archaeology", "Art", "Biology", "Chemistry", "Computing", "English", "French", "Geography", "History", "Maths", "Psychology"}; String x = "Geography"; int result = binarySearch(book, x); if (result == -1) Console.WriteLine("Element not present"); else Console.WriteLine("Element found at " + "index " + result); }}}
run
|
edit
|
history
|
help
0
IotaSeedGenerator
HashSet implementation
math 10.98
List of Lists example
Generic Factory pattern
Type win
Comp 3
PrivateConstructorToCreateSingleObject
Numbers in Interval Dividable by Given Number
2.10.4