Computer Science, asked by vinaykushwaha9839, 2 months ago

Write a program to search for a given ITEM in a given array X [n] using linear search technique.

If the ITEM is found move it at the top of the array. If the ITEM is not found insert it at the end of

the array.​

Answers

Answered by singhadityaanita
0

Answer:

Let's see an example of linear search in java where we are going to search an element sequentially from an array.

public class LinearSearchExample{

public static int linearSearch(int[] arr, int key){

for(int i=0;i<arr.length;i++){

if(arr[i] == key){

return i;

}

}

return -1;

Similar questions