snowmanJS
#include <iostream>
using namespace std;
#define SIZE 5
using ARR=int(&)[SIZE];
void sortAtoZ(ARR a)
{
for(int i=0;i<SIZE-1;++i)
{
for(int j=i+1;j<SIZE;++j)
{
if(a[i]>a[j])
{
int temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
}
void isArr(const int &n, const ARR a )
{
auto beg=begin(a);
auto ending=end(a);
while(beg!=ending)
{
auto half=(ending-beg)/2+beg;
if(n>*half)
beg=half+1;
if(n<*half)
ending=half;
if(n==*half)
break;
}
if(beg!=ending)
cout<<n<<"是数组的元素"<<endl;
else
cout<<n<<"不是数组的元素"<<endl;
}
int main()
{
int a[SIZE]={0};
cout<<"请输入"<<SIZE<<"个整数:"<<endl;
for(auto &val : a)
cin>>val;
sortAtoZ(a);
cout<<"排序后的数组为:"<<endl;
for(auto &val : a)
cout<<val<<" ";
cout<<endl;
int n;
cout<<"请输入一个整数:"<<endl;
cin>>n;
isArr(n,a);
return 0;
}