#include <stdio.h>
int a[101],n;
void quicksort(int left, int right) {
int i, j, t, temp;
if(left > right)
return;
temp = a[left];
i = left;
j = right;
while(i != j) {
while(a[j] >= temp && i < j)
j--;
while(a[i] <= temp && i < j)
i++;
if(i < j)
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
a[left] = a[i];
a[i] = temp;
quicksort(left, i-1);
quicksort(i+1, right);
}
int search(int a[],int x,int n)
{
int low=0,high=n-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==x)
return mid;
else if(x<a[mid])
high=mid-1;
else
low=mid+1;
}
return -1;
}
int main()
{
int i,k,j;
printf("Please input quantity of Key :\n");
scanf("%d", &n);
printf("Please input each key :\n");
for(i = 0; i < n; i++)
scanf("%d", &a[i]);
quicksort(0, n-1);
for(i = 0; i <n; i++)
printf("%d ", a[i]);
printf("\n");
printf("Please input Key to find :\n");
scanf("%d",&k);
j=search(a,k,n);
if(j!=-1)
printf("Found at %d.\n",j);
else
printf("Not found!\n");
printf("Please input another Key to find :\n");
scanf("%d",&k);
j=search(a,k,n);
if(j!=-1)
printf("Found at %d.\n",j);
else
printf("Not found!\n");
return 1;
}