Transferred from: http://www.lishiyu.cn/post/45.html
The dichotomy (binary lookup)-----------high efficiency, but requires a sequence of sequences and a small range of use
15/2 Take 7 not 8
/** Binary search algorithm---recursive algorithm **/intBinsearch (intArray[],intLow,intHighintkey) { if(low<=High ) { intMid = (low + high)/2; if(Key = =Array[mid])returnmid; Else if(Key <Array[mid])returnBinsearch (array, Low, mid-1, key); Else if(Key >Array[mid])returnBinsearch (Array, mid+1, high, key); } Else return-1;}/** Binary Lookup------Non-recursive algorithm **/intBinsearch (intArray[],intSizearray,intkey) { intlow=0; intHigh= sizearray-1; intmid; while(low<=High ) {Mid= (low + high)/2; if(Key = =Array[mid])returnmid; Else if(Key <Array[mid]) high= Mid-1; Else if(Key >Array[mid]) Low= Mid +1; } return-1;}
Data structure--two points find "go"