diff --git a/Chapter12/Chap12-6.js b/Chapter12/Chap12-6.js index 2e567d0..ae96a5a 100644 --- a/Chapter12/Chap12-6.js +++ b/Chapter12/Chap12-6.js @@ -1,13 +1,11 @@ + function selectionSort() { - var min, temp; for (var outer = 0; outer <= this.dataStore.length-2; ++outer) { - min = outer; for (var inner = outer + 1; inner <= this.dataStore.length-1; ++inner) { - if (this.dataStore[inner] < this.dataStore[min]) { - min = inner; + if (this.dataStore[inner] < this.dataStore[outer]) { + swap(this.dataStore, inner, outer); } } - swap(this.dataStore, outer, min); } }