01- complexity of the 3-minute find - Function Problems

01- complexity of the 3-minute find - Function Problems

Problem-solving Code

Position BinarySearch( List L, ElementType X )
{
    Position ret=NotFound;
    Position left=1,right=L->Last;
    Position loc;
    while(left<=right){
        loc=(left+right)/2;
        if(X==L->Data[loc]){
            ret=loc;
            break;
        }else if(X>L->Data[loc]){
            left=loc+1;
        }else{
            right=loc-1;
        }
    }
    return ret;
}

Test Results

Here Insert Picture Description

Finishing problem

Published 10 original articles · won praise 0 · Views 92

Guess you like

Origin blog.csdn.net/Aruasg/article/details/104792435