2016-07-16 11:01:51 +00:00
|
|
|
|
|
|
|
|
2016-07-29 18:47:32 +00:00
|
|
|
def simple_bubble_sort(int_list):
|
2016-07-29 19:31:20 +00:00
|
|
|
count = len(int_list)
|
|
|
|
swapped = True
|
|
|
|
while (swapped):
|
|
|
|
swapped = False
|
|
|
|
for j in range(count - 1):
|
|
|
|
if (int_list[j] > int_list[j + 1]):
|
|
|
|
int_list[j], int_list[j + 1] = int_list[j + 1], int_list[j]
|
|
|
|
swapped = True
|
|
|
|
return int_list
|
2016-07-29 18:47:32 +00:00
|
|
|
|
|
|
|
|
2016-07-29 19:14:30 +00:00
|
|
|
def main():
|
2016-07-29 19:31:20 +00:00
|
|
|
try:
|
|
|
|
print("Enter numbers separated by spaces:")
|
|
|
|
s = raw_input()
|
|
|
|
inputs = list(map(int, s.split(' ')))
|
|
|
|
if len(inputs) < 2:
|
|
|
|
print('No Enough values to sort!')
|
|
|
|
raise Exception
|
2016-07-29 19:14:30 +00:00
|
|
|
|
2016-07-29 19:31:20 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
else:
|
|
|
|
sorted_input = simple_bubble_sort(inputs)
|
|
|
|
print('\nSorted list (min to max): {}'.format(sorted_input))
|
2016-07-29 18:47:32 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-07-29 19:31:20 +00:00
|
|
|
print('==== Bubble Sort ====\n')
|
|
|
|
main()
|