I am trying to make a simple bubble sort, and the if statement i'm using to sort the numbers in my array is not running. Can anybody help me get this to run?
Here is my code:
def Bubble( a ):
Flag = False
while not Flag:
Flag = True
for i in range(0, len(a), -1):
if a[i] > a[i+1]: #this if statement isn't running
a[i], a[i + 1] = a[i + 1], a[i]
print("hi")
Flag = False
def main():
a = GRN(10)
acopy = a[:]
Bubble(a)
acopy.sort()
print(a==acopy)
print(a)
print(acopy)
main()
Aucun commentaire:
Enregistrer un commentaire