Advertisement
Avdluna

Untitled

Jan 17th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # coding: utf-8
  2. # Merge
  3. # Amanda Luna [116210896] / UFCG
  4.  
  5. def merge(lista1,lista2) :
  6.    
  7.     lista = lista1+lista2
  8.    
  9.     for i in range(len(lista)) :
  10.        
  11.         trocas = mergestep(lista,len(lista)-1)
  12.        
  13.         if trocas == 0 :
  14.             return
  15.            
  16.     return lista
  17.  
  18. def mergestep (lista,limite) :
  19.    
  20.     trocas = 0
  21.    
  22.     for i in range(len(lista)-1) :
  23.        
  24.         if lista[i] >= lista[i+1] :
  25.             lista[i],lista[i+1] = lista[i+1],lista[i]
  26.             trocas += 1
  27.        
  28.     return trocas
  29.    
  30. l1 = [3,7,9,11,14]
  31. l2 = [2,4,10,11,13,19,21,43]
  32. assert merge(l1,l2) == [2, 3, 4, 7, 9, 10, 11, 11, 13, 14, 19, 21, 43]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement