III search algorithm

xiaoxiao2021-03-06  62

#include "stdio.h"

INT binarysearch (const Int a [], int key, int N)

{

Int low, mid, high;

Low = 0;

HIGH = N - 1;

While (low <= high)

{

MID = (low high) / 2;

IF (a [MID]

Low = MID 1;

Else IF (a [MID]> Key)

HIGH = MID - 1;

Else

Return MID;

}

Return -1;

//test:

Int main () {

INT A [] = {-2, -4, 0, 5, 11, 13};

Printf ("BinarySearch:% D / N", BinarySearch (A, 13, SIZE));

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-117227.html

New Post(0)