uccjshrimpton

Ugly Bubble Sort

May 22nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. def bubble_sort(int_list):
  2.     num_1 = 0
  3.     num_2 = 0
  4.     counter = 0
  5.     complete = False
  6.    
  7.     while complete == False:
  8.  
  9.         swaps = 0
  10.         while counter < len(int_list) - 1:
  11.            
  12.             if int_list[counter] > int_list[counter+1]:
  13.                 num_1 = int_list[counter]
  14.                 num_2 = int_list[counter+1]
  15.                 int_list[counter+1] = num_1
  16.                 int_list[counter] = num_2
  17.                 swaps += 1
  18.                
  19.             counter += 1
  20.  
  21.         if swaps == 0:
  22.             complete = True
  23.        
  24.         counter = 0
  25.  
  26.     return int_list
Advertisement
Add Comment
Please, Sign In to add comment