Last active
June 26, 2021 06:30
-
-
Save prakash-pun/f777d1cec350c2eece74da97da13a739 to your computer and use it in GitHub Desktop.
Bubble Sort Algorithm
This file contains 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
# Bubble sort algorithm | |
def bubbleSort(dataset): | |
# TODO: start with the array length and decrement each time | |
for i in range(len(dataset) -1, 0, -1): | |
for j in range(i): | |
if dataset[j] > dataset [j+1]: | |
temp = dataset[j] | |
dataset[j] = dataset[j+1] | |
dataset[j+1] = temp | |
print("Current state: ", dataset) | |
def main(): | |
list1 = [1,30,20,4,19,43,34,54] | |
bubbleSort(list1) | |
print("Result: ",list1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment