using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Linkedlist
{
class Program
{
static public int[] numsort(int[] x)
{
int[] a = x;
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a.Length - 1; j++)
{
if (a[j] > a[j + 1])
{
int temp;
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
return a;
}
static public int binarySerach(int[] x,int find)
{
int left = 0;
int right = x.Length-1;
int mid;
while(left <= right)
{
mid = (left + right) / 2;
if (find == x[mid])
return mid;
else if (find < x[mid])
{
right = mid - 1;
}
else
left = mid + 1;
}
return -1;
}
static public void output(int[] x)
{
for(int i=0;i<x.Length;i++)
{
Console.Write(x[i]+" ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
Random r = new Random();
int find = 5;
int[] x = new int[10];
for(int i=0;i<10;i++)
{
x[i] = r.Next(10) + 1;
}
numsort(x);
output(x);
int c = binarySerach(x, find);
Console.WriteLine("Find : " + find + " Index : " + (c+1));
Console.ReadLine();
}
}
}