char sort using lenear search code example
Example 1: how to do a linear searc in java
public static int linear(int[] arr, int keyValue)
{
int pos = -1;
for (int i = 0; i < arr.length; i++)
{
if (arr[i] == keyValue)
{
pos = i;
break;
}
}
return pos;
}
Example 2: linear search
def global_linear_search(target, array)
counter = 0
results = []
while counter < array.length
if array[counter] == target
results << counter
counter += 1
else
counter += 1
end
end
if results.empty?
return nil
else
return results
end
end