数据结构经典搜索算法

//顺序查找
int seq_search(int* arrays, int len,int val)
{
	if (NULL == arrays || len < 2)
		return 0;

	for (int i=0;i val) 
		{
			right = mid - 1;
		}

		if (arrays[mid] < val)
			left = mid + 1;

	}

	return -1;
}

//插入查找
int insert_search(int* arrays, int left,int right, int val)
{
	if (NULL == arrays || left > right)
		return -1;

	int mid = left + (val - arrays[left]) / (arrays[right] - arrays[left]) * (right - left);

	if (arrays[mid] == val)
		return mid;

	if (arrays[mid] > val)
		return insert_search(arrays, left, mid - 1, val);

	if (arrays[mid] < val)
		return insert_search(arrays, mid + 1, right, val);
}


//斐波那契数列查找
void Fibonacci(int *F,int max_len) 
{
	if (NULL == F || max_len < 2)
		return ;

	F[0] = 0;
	F[1] = 1;

	for (int i=2;i Fibo[k] - 1)
		++k;

	int* tmp_vals = new int[Fibo[k] - 1];

	for (int i=0;i

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