Created
July 13, 2017 04:29
-
-
Save sujaykundu777/3a49a4c03724624f10f8deb6afe079a6 to your computer and use it in GitHub Desktop.
Linear Search Using Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title> Linear Search </title> | |
<script type="text/javascript"> | |
function linear_search(){ | |
var found=0; | |
var size= parseInt(prompt("Enter the size of an array")); | |
var a = new Array(size); | |
for (var i=0; i<a.length; i++){ | |
a[i] = parseInt(prompt("Enter Array Elements")); | |
} | |
var input = parseInt(prompt("Enter the Key Element to Search :")); | |
for(var i=0;i<a.length;i++){ | |
if(input == a[i]){ | |
found=1; | |
break; | |
} | |
} | |
if(found==1){ | |
document.writeln("Element Found at " + a[i] + "Found at Position :" + i); | |
} | |
else { | |
document.writeln("Element Not Found !"); | |
} | |
} | |
</script> | |
</head> | |
<body onload="linear_search()"> </body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment