What is searching?
Ans: The searching operation is used to search an element in an array.
I/P: An array A[l.......u] of n elements and the key-value.
O/P: Return the index position with a successful message.
DS: An array A[l.......u]
- i=0, found=0, location=0 //found=0 indicates search is not finished and unsuccessful.
- while(i<=u) and found=0
- if(A[i]=key) then
- found=1
- location=i
- else
- i=i+1
- End if
- End while
- if found=1 then
- Print"Search is successful: Key is present in the array at location"
- else
- Print"Search is unsuccessful: Key is not present in the array"
- End if
- Stop.
0 Comments