C++数组的二分法查找

#include 
using namespace std;
/*二分法查找*/
int find(int, int [], int);//二分法查找
void line(int [], int);//冒泡排序
int main()
{
	int a[] = {13,2,4,7,9,123,456,5,8,12,666,888,999,1234,3,11,22};
	int n = sizeof(a)/sizeof(int);
	line(a,n);//(按址传递)传递数组名,即数组的地址
	int num;
	while (num != -111)
	{
		cout<<"请输入你要查找的数字:";
		cin>>num;
		int i = find(num, a, n);
		if (i == -1)
		{
			cout<<"未找到你输入的数字。"<a[j+1])
			{
				t = a[j];
				a[j] = a[j+1];
				a[j+1] = t;
			}
		}
	}
	cout<<"自动排序后的a[]={";
	for (i=0; i

你可能感兴趣的:(C/C++)