Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
12
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 = Console.ReadLine(); 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
Encrypt Decrypt
sleep thread
Type win
Cotton Farm
111
deletevowels
Datediff in c#
Split IPs to 8 and 16
Delegates
sdfghnjmkuyhtgrfed