Guest User

boggo_sort.py

a guest
Jun 15th, 2021
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import random as rnd
  2.  
  3. def verificar(arreglo):
  4.     for i in range(0, len(arreglo)-1):
  5.         if arreglo[i] > arreglo[i+1]:
  6.             return False
  7.     return True
  8.  
  9. def ordenar(arreglo):
  10.     while not(verificar(arreglo)):
  11.         posA = rnd.randint(0, len(arreglo)-1)
  12.         posB = rnd.randint(0, len(arreglo)-1)
  13.  
  14.         aux = arreglo[posA]
  15.         arreglo[posA] = arreglo[posB]
  16.         arreglo[posB] = aux
  17.  
  18.     return arreglo
  19.  
  20. arreglo = [3,2,1,4]
  21.  
  22. print(ordenar(arreglo))
  23.  
Advertisement
Add Comment
Please, Sign In to add comment