Question #259474

BINARY(ARRAY,LB,UB,ITEM,LOC) which finds the location LOC where ITEM appears in ARRAY


Expert's answer

# 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 + 1then:
  Write: ITEM is not in the array DATA
else:
  Write: LOC is the location of ITEM
    Exit
LATEST TUTORIALS
APPROVED BY CLIENTS