var optimized_bubble; var optimized_cocktail; var numbers = Array(); function populate(length, min_value, max_value) { for(var input = 0; input < length; input++) { numbers[input] = Math.round((max_value - min_value) * Math.random() + min_value); } } function reset() { optimized_bubble.reset(); optimized_cocktail.reset(); } function sort() { optimized_bubble.sort(); optimized_cocktail.sort(); } function repopulate() { populate(25, -100, 100); optimized_bubble.copy(numbers); optimized_cocktail.copy(numbers); } function go() { populate(25, -100, 100); optimized_bubble = new sort_array('optimized_bubble', numbers.length); optimized_bubble.copy(numbers); optimized_bubble.sort = optimized_bubble_sort; optimized_cocktail = new sort_array('optimized_cocktail', numbers.length); optimized_cocktail.copy(numbers); optimized_cocktail.sort = optimized_cocktail_sort; document.getElementById('populate').onclick = repopulate; document.getElementById('reset').onclick = reset; document.getElementById('sort').onclick = sort; }