标签:pad class can arch std binary ret print rip
#include<cstdio> int binary_search(int arr[],int SizeOfArray,int key); int binary_search(int arr[],int SizeOfArray,int key){ int left=0,mid; int right=SizeOfArray-1; while(left<=right){ mid=(left+right)/2; if(key==arr[mid]) printf("%d",mid); break; if(key<arr[mid]) right=mid-1; if(key>arr[mid]) left=mid+1; } return -1; } int main() { int key; scanf("%d",&key); int a[10]={1,2,3,4,5,6,7,8,9,10}; binary_search(a,9,key); return 0; }
/* 1 2 3 4 5 6 7 8 9 */
标签:pad class can arch std binary ret print rip
原文地址:http://www.cnblogs.com/anstoner/p/6388945.html