Scripts.FranciscoCharrua.com
Index
News
Downloads
GNOME-SORT.JS
comparisons:
swaps:
Gnome sort, originally called stupid sort, works by keeping and expanding on a sorted beginning of the array. Every time it finds a pair of elements in the wrong order, it bubbles the light one towards the beginning until it's in the right place.
sort.js
bubble-sort.js
optimized-bubble-sort.js
selection-sort.js
cocktail-sort.js
optimized-cocktail-sort.js
odd-even-sort.js
comb-sort.js
quick-sort.js
gnome-sort.js
optimized-gnome-sort.js
compare sort algorithms
function gnome_sort() { this.gnome_sort_acending_order = function(input) { if(input < this.inputs.length) { if(this.in_ascending_order(input - 1, input)) { setTimeout(this.name + '.gnome_sort_acending_order(' + (input + 1) + ');', this.speed); } else { setTimeout(this.name + '.gnome_sort_swap(' + input + ');', this.speed); } } } this.gnome_sort_swap = function(input) { this.swap(input - 1, input); if(input > 1) { input--; } else { input++; } setTimeout(this.name + '.gnome_sort_acending_order(' + input + ');', this.speed); } this.gnome_sort_acending_order(1); } var gnome; function go() { gnome = new sort_array('gnome', 10); gnome.populate(-100, 100); gnome.sort = gnome_sort; document.getElementById('gnome_populate').onclick = function(){gnome.populate(-100, 100);} document.getElementById('gnome_reset').onclick = function(){gnome.reset();} document.getElementById('gnome_sort').onclick = function(){gnome.sort();} }