# merge con pares

unknown
python
3 years ago
3.1 kB
3
Indexable
Never
```# importo random
import random

# función de ordenamiento
def ordenamiento(vector, tamaño):
intercambio = True
while intercambio:
intercambio = False
for i in range(0,tamaño-1):
if vector[i] > vector[i+1]:
intercambio = True
swap = vector[i]
vector[i] = vector[i+1]
vector[i+1] = swap

# defino cantidad de elementos (sobredimensiono el C)

# defino vectores

# relleno los vectores
vector_a[i] = random.randint(1, 20)

vector_b[i] = random.randint(1, 20)

# ordeno los vectores

print("VECTOR A:")
print(vector_a[i], end = " ")

print(" ")
print("VECTOR B:")
print(vector_b[i], end = " ")
print(" ")

# inicializo índices
indice_a = 0
indice_b = 0
indice_c = 0

# mezclo
if (vector_a[indice_a] < vector_b[indice_b]):
if (vector_a[indice_a] % 2 == 0):
vector_c[indice_c] = vector_a[indice_a]

indice_a = indice_a + 1
indice_c = indice_c + 1
else:
indice_a = indice_a + 1
else:
if (vector_b[indice_b] % 2 == 0):
vector_c[indice_c] = vector_b[indice_b]

indice_b = indice_b + 1
indice_c = indice_c + 1
else:
indice_b = indice_b + 1

# mezclo en caso de que hayan sobrado
# con el vector a
if (vector_a[indice_a] % 2 == 0):
vector_c[indice_c] = vector_a[indice_a]

indice_a = indice_a + 1
indice_c = indice_c + 1
else:
indice_a = indice_a + 1

# con el vector b
if (vector_b[indice_b] % 2 == 0):
vector_c[indice_c] = vector_b[indice_b]

indice_b = indice_b + 1
indice_c = indice_c + 1
else:
indice_b = indice_b + 1

# saco la cantidad util del vector c
if vector_c[i] > -1:

# defino un nuevo vector c