Skip to content

Instantly share code, notes, and snippets.

@clara-shin
Last active May 28, 2018 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clara-shin/43a4b210a67699c760f4ac01ae2e2664 to your computer and use it in GitHub Desktop.
Save clara-shin/43a4b210a67699c760f4ac01ae2e2664 to your computer and use it in GitHub Desktop.
순차탐색 알고리즘
function sequentialSearch(arr,n,x){
for(let i=0; i < n; i++){
if(x === arr[i]) return i;
}
return -1; //탐색실패 시 리턴 -1
}
/*
arr=[0,1, ...n-1];에서 x를 찾는 알고리즘
배열 arr, n 은 data 개수, x 는 찾고자 하는 data
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment