Added selection sort algorithm in javascript (#33)
parent
6c8e1697ea
commit
4c9fab8025
|
@ -0,0 +1,15 @@
|
||||||
|
let sort = [12,6,3,88,1,4,8]
|
||||||
|
|
||||||
|
for(let i=0; i<sort.length; i++){
|
||||||
|
for(let j=0; j<sort.length; j++){
|
||||||
|
// comparing array elements
|
||||||
|
if(sort[j]>sort[i]){
|
||||||
|
//swaping elements
|
||||||
|
let temp = sort[i];
|
||||||
|
sort[i]=sort[j];
|
||||||
|
sort[j]= temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(sort)
|
Loading…
Reference in New Issue