1. [Initialize segment variables.]
Set BEG : = LB, END : = UB and MID = INT((BEG+END)/2).
2. Repeat Steps 3 and 4 while BEG < END and DATA[MID] != ITEM
3. If ITEM < DATA[MID], then:
Set END : = MID - 1.
Else:
Set BEG : = MID + 1.
[End of Structure.]
4. Set MID : = INT((BEG + END)/2).
[End of Step 2 Loop.]
5. If DATA[MID] = ITEM, then:
Set LOC : = MID.
Else:
Set LOC : = NULL.
[End of If Structure.]
6. Exit.
0 comments:
Post a Comment