我在写一个递归二进制搜索程序。这是迄今为止我所拥有的。这个程序的参数是它包含2个函数,主函数和第二个函数,它们将对它传递的值进行二进制排序。该项目工程,但它不递归搜索功能,我不认为它使用二进制搜索...提高我的二进制搜索程序为递归的吗?
/* ex06_18.c */
#include <stdio.h>
#define SIZE 10
/* function prototype */
void someFunction(const int b[], int startIndex, int size);
/* function main begins program execution */
int main(void)
{
int a[ SIZE ] = { 8, 3, 1, 2, 6, 0, 9, 7, 4, 5 }; /* initialize a */
printf("Answer is:\n");
someFunction(a, 0, SIZE);
printf("\n");
return 0; /* indicates successful termination */
}
void someFunction(const int b[], int startIndex, int size)
{
if (startIndex < size) {
someFunction(b, startIndex + 1, size);
printf("%d ", b[ startIndex ]);
} /* end if */
} /* end function someFunction */
“该项目工程” - 除非你有一个完全不同的概念,“搜索”比其他人。 “它不会递归地搜索函数” - 仅仅因为它不搜索;它显然是递归的。 “我不认为它使用二分搜索” - 你不觉得?你是否在课堂上跳过讨论,没有阅读关于该主题的教科书?即使如此,通过谷歌提供的引用googol。 “二进制排序” - 等待,现在你想排序?排序,搜索和打印出所有的值都是三种不同的东西。 –