Algorithms-and-Data-Structures/Python-Bubble-Sort/bubbleSort.py
2024-05-02 20:14:36 +01:00

18 lines
364 B
Python

nums = [8,90,19,12,7,6,55,98];
for i in range(len(nums)-2):
swapped = False;
for j in range(len(nums)-1-i):
if j == 0:
j = 1;
if nums[j-1] > nums[j]:
temp = nums[j];
nums[j] = nums[j-1];
nums[j-1] = temp;
swapped = True;
if not swapped:
break;
print(nums);