diff --git a/README.md b/README.md index cda093b..0e605c1 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ Go ahead and add a one line intro about you and add your favorite emoji (you can - Hi, my name is Brandon and my favorite emoji is 🍔 +- Hi, my name is Hasan and my favorite emoji is 😅 + ## Conclusion Thank you for the overwhelming amount of contributions! I hope that everybody made their 4 pull requests for Hacktoberfest, and that your journey to open source doesn't end here. I am *slowly* getting through the pull requests. Check back if you don't see your changes in this repo! Best of luck :) diff --git a/sorting/bubble.pyc b/sorting/bubble.pyc deleted file mode 100644 index 449664e..0000000 Binary files a/sorting/bubble.pyc and /dev/null differ diff --git a/sorting/heap.pyc b/sorting/heap.pyc deleted file mode 100644 index d4b7f77..0000000 Binary files a/sorting/heap.pyc and /dev/null differ diff --git a/sorting/selection.py b/sorting/selection.py new file mode 100644 index 0000000..359e04a --- /dev/null +++ b/sorting/selection.py @@ -0,0 +1,16 @@ +def selection(numbers): + + # Traverse through the array + for i in range(len(numbers)): + + # Find the index of the minimum element in remaining sorted array + min_index = i + for j in range(i+1, len(numbers)): + if numbers[min_index] > numbers[j]: + min_index = j + + # Swap the found minimum element with this index + numbers[i], numbers[min_index] = numbers[min_index], numbers[i] + + #return the sorted array + return numbers \ No newline at end of file diff --git a/tests.py b/tests.py index 270c350..c1d5389 100644 --- a/tests.py +++ b/tests.py @@ -55,3 +55,12 @@ print "Bucket Sort incorrect" except: print "Bucketsort function errored or is incomplete" + +try: + from selection import selection + if(selection(list(nums)) == sortedNums): + print "selectionsort success!" + else: + print "selectionsort incorrect." +except: + print "selectionsort function errored or is incomplete." \ No newline at end of file