afusion.py

Created by bilouclic

Created on December 15, 2024

812 Bytes


def fusion(lst1, lst2):
n1 = len(lst1)
n2 = len(lst2)
lst12 = [0] * (n1 + n2)
i1 = 0  # indice courant dans 
i2 = 0  # indice courant dans 
i = 0   # indice courant dans 
# Tant que le parcours de l lst2
# de lst2 puis on copie dans  
while i1 < n1 and i2 < n2 :
if lst1[i1] < lst2[i2]:
lst12[i] = lst1[i1]
i1 = i1 + 1
else:
lst12[i] = lst2[i2]
i2 = i2 + 1
i += 1
# Tant que le parcours de la l
while i1 < n1:
lst12[i] = lst1[i1]
i1 = i1 + 1
i = i + 1
# Tant que le parcours de la li
while i2 < n2:
lst12[i] = lst2[i2]
i2 = i2 + 1
i = i + 1
return lst12




condensé :
  
def fusion_2(tab1, tab2):
t = [0] * (len(tab1) + len(tab2))
i, j = 0, 0
for k in range(len(t)):
if i >= len(tab1) or 
(j < len(tab2) 
and tab1[i] > tab2[j]):
t[k] = tab2[j]
j = j + 1
else:
t[k] = tab1[i]
i = i + 1
return t

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.