Created
April 1, 2021 16:10
-
-
Save achjailani/6bfd21cc8b088e19bbc5b850061441aa to your computer and use it in GitHub Desktop.
Bubble sort algorithm in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lists = [3, 5, 7, 1, 10, 8, 9, 15]; | |
tmp=0 | |
''' | |
SORTING PROCESS IS HERE | |
''' | |
for i in range(len(lists)): | |
for y in range(0, len(lists) -1): | |
if lists[y] > lists[y+1]: | |
tmp = lists[y] | |
lists[y] = lists[y+1] | |
lists[y+1] = tmp | |
def prinList(): | |
for i in range(0,len(lists)): | |
print("%d " % lists[i], end='') | |
prinList() | |
print("\n\n") | |
print("ANOTHER WAY TO DO BUBBLE SORT") | |
''' | |
SORTING PROCESS IS HERE | |
OTHER SORTING PROCESS | |
''' | |
for i in range(len(lists)): | |
for y in range(0, len(lists)): | |
if lists[i] < lists[y]: | |
tmp = lists[i] | |
lists[i] = lists[y] | |
lists[y] = tmp | |
prinList() | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment