From 30a10892ebd198eb4a8b61aa769123c811d529c6 Mon Sep 17 00:00:00 2001 From: booboy Date: Sat, 11 May 2019 01:04:35 -0500 Subject: [PATCH] psuedocoded some stuff while multitasking --- algorithms/lib/algorithms/sorting.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/algorithms/lib/algorithms/sorting.rb b/algorithms/lib/algorithms/sorting.rb index 446839f..4b6b3fb 100644 --- a/algorithms/lib/algorithms/sorting.rb +++ b/algorithms/lib/algorithms/sorting.rb @@ -1,24 +1,23 @@ module Algorithms class Sorting - def selection(a) - # a is an Array + def selection(array) # from: https://www.tutorialspoint.com/data_structures_algorithms/selection_sort_algorithm.htm # Step 1 − Set MIN to location # Step 2 − Search the minimum element in the list # Step 3 − Swap with value at location MIN # Step 4 − Increment MIN to point to next element # Step 5 − Repeat until list is sorted + + # set a max + max = array.max + + # set the index of the min and use it with pop to make new array + index_of_min = array.index(array.min) + almost_sorted_array = array.pop(index_of_min) - counter = 0 - max = a.length - - a.map do |item| - #binding.pry - counter += 1 - end + incremented_index = array[index_of_min + 1] end - def insertion end