这个c语言程序的binary search貌似只有一个错了,但是不知道怎么改,求大神帮忙

/**
* helpers.c
*
* Helper functions for Problem Set 3.
*/

#include <cs50.h>
#include <stdio.h>
#include "helpers.h"

/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{ int c, first, last, middle, search;

printf("Enter number of elements\n");
value = get_int();

printf("Enter %d integers\n", n);
values[];
for (c = 0; c < n; c++)

printf("Enter value to find\n");
search = get_int();

first = 0;
last = n - 1;
middle = (first+last)/2;

while (first <= last) {
if ( values[middle] < value)
first = middle + 1;
else if ( values[middle] == value) {
printf("%d found at location %d.\n", search, middle+1);
break;
}
else
last = middle - 1;

middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d isn't present in the list.\n", value);

return 0;
}
/**
* helpers.c
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include <stdio.h>
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value,int values[], int n)
{ int c, first, last, middle;
printf("Enter number of elements\n");
n = get_int();
printf("Enter %d integers\n", n);
values[] = get_int;
for (c = 0; c < n; c++)
printf("Enter value to find\n");
value = get_int();
first = 0;
last = n - 1;
middle = (first+last)/2;
while (first <= last) {
if ( values[middle] < value)
first = middle + 1;
else if ( values[middle] == value) {
printf("%d found at location %d.\n", value, middle+1);
break;
}
else
last = middle - 1;
middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d isn't present in the list.\n", value);
return 0;
}
求改这个啊,原来那个不对

虽然这个程序自定义了输入函数,但是二分查找的逻辑是没有错的,不知道你说的错误是什么。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-07-29
第一行bool形放后头去,#include<......>后头
还有 第一行的#include<>要另起一行
相似回答