小编Rhy*_*hys的帖子

搜索算法的C代数意外结果

我已经为有序的整数数组实现了这个搜索算法.它适用于我提供的第一个数据集(500个整数),但在较长的搜索时失败.但是,所有这些集合都与我为分配实现的其他四种搜索算法完美配合.

这是在第178行返回seg故障的函数(由于意外的负m值).任何帮助将不胜感激.

码:

155 /* perform Algortihm 'InterPolationSearch' on the set
156  * and if 'key' is found in the set return it's index
157  * otherwise return -1 */
158 int
159 interpolation_search(int *set, int len, int key)
160 {
161   int l = 0;
162   int r = len - 1;
163   int m;
164
165   while (set[l] < key &&  set[r] >= key)
166   {
167
168     printf ("m = l + ((key - set[l]) * (r …
Run Code Online (Sandbox Code Playgroud)

c algorithm algebra

1
推荐指数
1
解决办法
119
查看次数

标签 统计

algebra ×1

algorithm ×1

c ×1