Ejemplo n.º 1
0
void testFindMidpoint() {
	ublas::vector<double> p1(3,2.0), p2(3,2.0), p3(3,0.0), p4(3,0.0);
	p2(2) = 1;
	p4(0) = 1;
	ublas::vector<double> result = findMidpoint(p1,p2,p3, p4);
	print("result", result);//yields 2, 1, 0
}
Ejemplo n.º 2
0
int binary_search(int value, int values[], int n, int *found)
{
    int min = 0;
    int max = n - 1;
    int mid = 0;
    mid = findMidpoint(&max, &min, &mid);
    
    while(*found == -1)
    {
        if(value == values[mid]) 
        {
            *found = 1;
            return (*found);
        }
        else if (max < min)
        {
            *found = 0;
            return (*found);
        }
        else
        {   
            
            if (values[mid] < value)
            {
                min = mid + 1;
                *found = -1;
                mid = findMidpoint(&max, &min, &mid);
             
            }
            else if (values[mid] > value)
            {
                max = mid - 1;
                *found = -1;
                mid = findMidpoint(&max, &min, &mid);
            }
            else
            {
                *found = 1;
                return *found;
            }
        } 
    }    
    
    return *found;
}
Ejemplo n.º 3
0
int main(void)
{
 int n = 7;
 int values[] = {4, 23, 81, 92, 102, 119, 145};
 int max = n - 1;
 int min = 0;
 int midpoint = findMidpoint(&max, &min);
 printf("the midpoint position is %i, and the midpoint value is %i\n", midpoint, values[midpoint]);
}