#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<memory.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#define mem(array) memset((array),0,sizeof((array)))
#define Qsort(array,len,cmp) qsort(array,len,sizeof(array[0]),cmp)
#define inf 0x7fffffff
#define MAXN 10+100
using namespace std;
int binarySearch(int* a, int n, int x, int flag = -1)
{ /**
binarySearch parameter description:
int * a a is an array that sorted from small to large
int n n is the length of array a
int x x is the search object
int flag flag is a return sign.
the function will return the index of the first object that equal to the value of object x if the object exists.
when the object is not exist, the function will return -1 while flag is -1,
or return the index of the last maximal object that less than
C++ 二分查找 binary search 模板
最新推荐文章于 2025-03-27 17:08:16 发布