using namespace std;
int main()
{
int i,j,t,n=0,num;
int a[10];
for (i=0;i<10;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
for (i=0;i<10;i++)
{
for (j=0;j<9-i;j++)
{
if (a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
cout<<"输入要查找的数据:"<<endl;
cin>>num;
cout<<"输出数组:"<<endl;
for (i=0;i<10;i++)
{
cout<<a[i]<<"\t";
if((i+1)%3==0)
{
cout<<endl;
}
}
cout<<endl;
int left=0,right=9,mid;
while (left<=right)
{
mid=(left+right)/2;
if (a[mid]==num)
{
cout<<"要查找的元素是:"<<endl;
cout<<"a["<<mid<<"]="<<num<<endl;
n++;
}
if (a[mid]<num)
{
left=mid+1;
}
else
{
right=mid-1;
}
}
if (n==0)
{
cout<<"要查找的元素不存在!"<<endl;
}
}