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

/***helpers.c**HelperfunctionsforProblemSet3.*/#include<cs50.h>#include<stdio.h>#incl... /**
* 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;
}
求改这个啊,原来那个不对
展开
 我来答
丿艾瑞灬莉娅
2018-07-29 · TA获得超过916个赞
知道小有建树答主
回答量:926
采纳率:78%
帮助的人:462万
展开全部
虽然这个程序自定义了输入函数,但是二分查找的逻辑是没有错的,不知道你说的错误是什么。
匿名用户
2018-07-29
展开全部
第一行bool形放后头去,#include<......>后头
还有 第一行的#include<>要另起一行
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式