Code in (c++)
// C++ Program to implement linear search
// algorithm iteratively
int linearSearch(vector v, int key) {
// We test all the elements of the vector
// v against the given key
for (int i = 0; i < v.size(); i++) {
// If the KEY IS FOUND
if (v[i] == key) {
return i;
}
}
// Return some value denoting KEY NOT FOUND
return -1;
}