diff --git a/README.md b/README.md index cda093b..968c374 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 🍔 +- Hello there. My name is David and my least not 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/combsort.py b/sorting/combsort.py index ced5aad..20ba3de 100644 --- a/sorting/combsort.py +++ b/sorting/combsort.py @@ -1,22 +1,14 @@ -function combsort(array input) - gap := input.size //initialize gap size - loop until gap = 1 and swaps = 0 - //update the gap value for a next comb. Below is an example - gap := int(gap / 1.25) - if gap < 1 - //minimum gap is 1 - gap := 1 - end if - i := 0 - swaps := 0 //see Bubble Sort for an explanation - //a single "comb" over the input list - loop until i + gap >= input.size //see Shell sort for similar idea - if input[i] > input[i+gap] - swap(input[i], input[i+gap]) - swaps := 1 // Flag a swap has occurred, so the - // list is not guaranteed sorted - end if - i := i + 1 - end loop - end loop -end function \ No newline at end of file +def combsort(numbers_list): + ordered = numbers_list.copy() + gap = len(numbers_list) # initial gap (first and last element) + swaps = True + while swaps or gap!=1: + swaps = False + for i in range(len(numbers_list)-gap): + if ordered[i] > ordered[i+gap]: # swaps without extra variable + ordered[i] = ordered[i+gap] - ordered[i] + ordered[i+gap] = ordered[i+gap] - ordered[i] + ordered[i] = ordered[i+gap] + ordered[i] + swaps = True + gap = max(gap-1, 1) # update gap, minimum gap is 1 + return ordered diff --git a/tests.py b/tests.py index 270c350..fe3e5b7 100644 --- a/tests.py +++ b/tests.py @@ -8,50 +8,59 @@ try: from bubble import bubble if(bubble(list(nums)) == sortedNums): - print "bubblesort success!" + print("bubblesort success!") else: - print "bubblesort incorrect." + print("bubblesort incorrect.") except: - print "bubblesort function errored or is incomplete." + print("bubblesort function errored or is incomplete.") try: from insertion import insertion if(insertion(list(nums)) == sortedNums): - print "insertionsort success!" + print("insertionsort success!") else: - print "insertionsort incorrect." + print("insertionsort incorrect.") except: - print "insertionsort function errored or is incomplete." + print("insertionsort function errored or is incomplete.") try: from merge import mergesort if(mergesort(list(nums)) == sortedNums): - print "mergesort success!" + print("mergesort success!") else: - print "mergesort incorrect." + print("mergesort incorrect.") except: - print "mergesort function errored or is incomplete." + print("mergesort function errored or is incomplete.") try: from quick import quick if(quick(list(nums)) == sortedNums): - print "quicksort success!" + print("quicksort success!") else: - print "quicksort incorrect." + print("quicksort incorrect.") except: - print "quicksort function errored or is incomplete." + print("quicksort function errored or is incomplete.") try: from heap import heap if(heap(list(nums)) == sortedNums): - print "Heap Sort success!" + print("Heap Sort success!") else: - print "Heap Sort incorrect." + print("Heap Sort incorrect.") except: - print "Heapsort function errored or is incomplete." + print("Heapsort function errored or is incomplete.") try: from bucket import bucket if(bucket(list(nums)) == sortedNums): - print "Bucket Sort success" + print("Bucket Sort success.") else: - print "Bucket Sort incorrect" + print("Bucket Sort incorrect.") except: - print "Bucketsort function errored or is incomplete" + print("Bucketsort function errored or is incomplete.") + +try: + from combsort import combsort + if(combsort(list(nums)) == sortedNums): + print("Comb Sort success biatch!") + else: + print("Comb Sort incorrect.") +except: + print("Comb Sort function errored or is incomplete.")