public class linearSearch {
public static void main(Integer key){
System.debug('Linear Search');
integer s = -1;
List<integer> lon = new List<integer> ();
lon.add(3);
lon.add(4);
lon.add(5);
lon.add(6);
System.debug('List: '+lon);
for(integer i = 0; i < lon.size(); i++)
{
if (key == lon[i])
{
s = 1;
}
}
if (s == 1)
{
System.debug('Element Found');
}
else
{
System.debug('Element Not Found');
}
}
}
//Run
// linearSearch.main(7);
cHVibGljIGNsYXNzIGxpbmVhclNlYXJjaCB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihJbnRlZ2VyIGtleSl7CiAgICAJU3lzdGVtLmRlYnVnKCdMaW5lYXIgU2VhcmNoJyk7CiAgICAJaW50ZWdlciBzID0gLTE7CiAgICAJTGlzdDxpbnRlZ2VyPiBsb24gPSBuZXcgTGlzdDxpbnRlZ2VyPiAoKTsKICAgIAlsb24uYWRkKDMpOwogICAgCWxvbi5hZGQoNCk7CiAgICAJbG9uLmFkZCg1KTsKICAgIAlsb24uYWRkKDYpOwogICAgCVN5c3RlbS5kZWJ1ZygnTGlzdDogJytsb24pOwogICAgCWZvcihpbnRlZ2VyIGkgPSAwOyBpIDwgbG9uLnNpemUoKTsgaSsrKQogICAgCXsKICAgICAgICAJaWYgKGtleSA9PSBsb25baV0pCiAgICAgICAgCXsKICAgICAgICAgICAgCXMgPSAxOwogICAgICAgIAl9CiAgICAJfQogICAgCWlmIChzID09IDEpCiAgICAJewogICAgICAgIAkJU3lzdGVtLmRlYnVnKCdFbGVtZW50IEZvdW5kJyk7CiAgICAJfQogICAgCWVsc2UKICAgIAl7CiAgICAgICAgCQlTeXN0ZW0uZGVidWcoJ0VsZW1lbnQgTm90IEZvdW5kJyk7CiAgICAJfQoJfQp9CgoKCgovL1J1bgoKLy8gbGluZWFyU2VhcmNoLm1haW4oNyk7