Problem:
We need to search an element from an list. We have variety of methods to search an element from an array but the simple way of search is "Linear Search" method. We just need a loop traversing the array and search for match. We can see two ways for achieving linear search in this post.
Method 1:
Here we just directly give the values of array and value to search in default , the code follows.
The loop takes range as 0,1,2,3,4 and traverse list elements. We have a conditional statement to check the key is in the list. If the key is found it returns output or else it does not display output.
Method 2:
In this method I has used functions and got inputs from the user, and the code follows.
Comments
Post a Comment