Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- public static class NumberFinder
- {
- public static bool BinaryNumberSearch(this int[] numbers, int findNumber)
- {
- var left = 0;
- var right = numbers.Length - 1;
- while (left < right)
- {
- var middle = (left + right) / 2;
- if (findNumber <= numbers[middle])
- right = middle;
- else
- left = middle + 1;
- }
- if (numbers[right] == findNumber)
- return true;
- return false;
- }
- }
- class Program
- {
- static void Main()
- {
- var leftBorder = int.Parse(Console.ReadLine());
- var rightBorder = int.Parse(Console.ReadLine());
- var findNumber = int.Parse(Console.ReadLine());
- int[] numbers = new int[] { 1, 5, 6, 3, 2, 2, -10};
- int[] intervalNumbers = new int[rightBorder - leftBorder + 1];
- Array.Copy(numbers, leftBorder, intervalNumbers, 0, intervalNumbers.Length);
- Array.Sort(intervalNumbers);
- Console.WriteLine(intervalNumbers.BinaryNumberSearch(findNumber));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement