Advertisement
LightProgrammer000

Bubble_sort [python3]

Feb 20th, 2020
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. '''
  2. Programa: Bubble sort
  3. '''
  4.  
  5. # Principal
  6. def main():
  7.  
  8.     lista = [1, 2, 3]
  9.  
  10.     print(buuble_sort(lista))
  11.  
  12. # Metodo: Maior elemento
  13. def buuble_sort(lista):
  14.  
  15.     i = 1
  16.     aux = 0
  17.  
  18.     # Estrutura de repeticao
  19.     while i < len(lista):
  20.  
  21.         # Reiniciando variavel
  22.         j = 0
  23.  
  24.         # Estrutura de repeticao
  25.         while j <= i:
  26.  
  27.             # Estrutura de decisao
  28.             if lista[i] > lista[j]:
  29.  
  30.                 # Troca de valores
  31.                 aux = lista[i]
  32.                 lista[i] = lista[j]
  33.                 lista[j] = aux
  34.  
  35.             # Incremento
  36.             j += 1
  37.  
  38.         # Incremento
  39.         i += 1
  40.  
  41.     return lista
  42.  
  43. # Execucao
  44. if __name__ == '__main__':
  45.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement