CaCao
01/04/2007, 12:50
Merhabalar elimde binary search ile ilgili bir algorithm var.
1.0 Let the bottom be the initial array elements.
2.0 Let the top be the last array elements.
3.0 Let found false.
4.0 Repeat as long as bottom is not greater than top and target has not been found.
4.1 Let the middle be subscript of the element half way between bottom
and top.
4.2 If the element middle is target
4.2.1 Set found to true and index ot middle.
4.3 Let top be the middle-1
bunun programini su sekilde yaptim fakat olmadi acaba yardim edebilirmisiniz?
#include<stdio.h>
#include<stdlib.h>
#define SIZE 50
int
main(void)
{
int found, result, top, bottom,ary[SIZE];
found=0;
while(bottom>=top && found=0)
{
result= (bottom+top)/2;
if(ary[result]==found)
found=1;
else
if(ary[result]>found)
found=result-1;
else
found=result+1;
}
system("pause");
return(0);
}
cok acil lazim
tesekkur ederim simdiden
1.0 Let the bottom be the initial array elements.
2.0 Let the top be the last array elements.
3.0 Let found false.
4.0 Repeat as long as bottom is not greater than top and target has not been found.
4.1 Let the middle be subscript of the element half way between bottom
and top.
4.2 If the element middle is target
4.2.1 Set found to true and index ot middle.
4.3 Let top be the middle-1
bunun programini su sekilde yaptim fakat olmadi acaba yardim edebilirmisiniz?
#include<stdio.h>
#include<stdlib.h>
#define SIZE 50
int
main(void)
{
int found, result, top, bottom,ary[SIZE];
found=0;
while(bottom>=top && found=0)
{
result= (bottom+top)/2;
if(ary[result]==found)
found=1;
else
if(ary[result]>found)
found=result-1;
else
found=result+1;
}
system("pause");
return(0);
}
cok acil lazim
tesekkur ederim simdiden