Advertisement
cardel

Untitled

May 9th, 2021
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 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.  
  8.   return True
  9.  
  10. def ordenar(arreglo):
  11.   while not(verificar(arreglo)):
  12.     posA = rnd.randint(0, len(arreglo)-1)
  13.     posB = rnd.randint(0, len(arreglo)-1)
  14.  
  15.     aux = arreglo[posA]
  16.     arreglo[posA] = arreglo[posB]
  17.     arreglo[posB] = aux
  18.  
  19.   return arreglo
  20.  
  21. arreglo = [4,5,1,2,3,9,8,10,-1]
  22.  
  23. print(ordenar(arreglo))
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement