C/C++
int search(int arrayforsearch[], int n, int x)
{
int i;
for (i=0; i<n; i++)
if (arrayforsearch[i] == x)
return i;
return -1;
}
python:-
def search(arrayforsearch, x):
for i in range(len(arrayforsearch)):
if arrayforsearch[i] == x:
return i
return -1
JAVA:-
class LinearSearch
{
static int search(int arrayforsearch[], int n, int x)
{
for (int i = 0; i < n; i++)
{
if (arrayforsearch[i] == x)
return i;
}
return -1;
}
}
No comments:
Post a Comment