a nonempty linear array DATA with N elements in it and a ITEM of information / element are given. a linear search algorithm is to find the ITEM in DATA and if so then location LOC of ITEM in DATA to print out.
- set K :=1 and LOC:=0. [ initialize ]
- while LOC=0 and K<=N, repeat step 3 and 4.
- if ITEM = DATA[K], then set LOC :=K.
- set K:=K+1. [increment counter ] [end of step 2 loop ]
- If : LOC=0 then: Write: ITEM isn't in the array DATA. Else: Write: LOC is the location of ITEM..
- Exit.
No comments:
Post a Comment