BINARY(ARRAY,LB,UB,ITEM,LOC) which finds the location LOC where ITEM appears in ARRAY
# This algorithm finds the location of LOC where ITEM appears in Array
Set DATA[N+1]:=ITEM
Set LOC = 1
Repeat while DATA[LOC]!= ITEM:
Set LOC := LOC + 1
[End of loop]
if LOC = N + 1, then:
Write: ITEM is not in the array DATA
else:
Write: LOC is the location of ITEM
Exit
Comments
Leave a comment