Comb Sort | To find next gap from current ; Shrink gap by Shrink factor ; Function to sort arr [ ] using Comb Sort ; Initialize gap ; Initialize swapped as true to make sure that loop runs ; Keep running while gap is more than 1 and last iteration caused a swap ; Find next gap ; Initialize swapped as false so that we can check if swap happened or not ; Compare all elements with current gap ;  ;  ; Driver code to test above
def getNextGap ( gap ) : NEW_LINE INDENT gap = ( gap * 10 ) / 13 NEW_LINE if gap < 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return gap NEW_LINE DEDENT def combSort ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE gap = n NEW_LINE swapped = True NEW_LINE while gap != 1 or swapped == 1 : NEW_LINE INDENT gap = getNextGap ( gap ) NEW_LINE swapped = False NEW_LINE for i in range ( 0 , n - gap ) : NEW_LINE INDENT if arr [ i ] > arr [ i + gap ] : NEW_LINE DEDENT DEDENT DEDENT / * Swap arr [ i ] and arr [ i + gap ] * / NEW_LINE INDENT arr [ i ] , arr [ i + gap ] = arr [ i + gap ] , arr [ i ] NEW_LINE DEDENT / * Set swapped * / NEW_LINE INDENT swapped = True NEW_LINE DEDENT arr = [ 8 , 4 , 1 , 3 , - 44 , 23 , - 6 , 28 , 0 ] NEW_LINE combSort ( arr ) NEW_LINE print ( " Sorted ▁ array : " ) NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT print ( arr [ i ] ) , NEW_LINE DEDENT