DocumentaciónINTERCAMBIAR(a, b)
Nombre
INTERCAMBIAR - Intercambia el contenido de dos variables compatibles.
Sinopsis
INTERCAMBIAR(a, b)
Descripcion
Intercambia el contenido de dos variables o elementos modificables de tipos compatibles.
Se usa para ordenamientos, rotaciones de valores y algoritmos que necesitan permutar datos in place.
Comportamiento
- Modifica ambos argumentos por referencia.
- Soporta numeros, strings y elementos de estructuras compatibles del runtime.
- No retorna valor.
Funciones API relacionadas
TIPO()COMPARAR()
Parámetros
| Parámetro | Tipo | Descripción |
|---|---|---|
| a | ANY | Primera variable. |
| b | ANY | Segunda variable. |
Valor de retorno
VACIO - No retorna valor; modifica ambos argumentos por referencia.
Ejemplo
ejemplo.blox
FUNCION PRINCIPAL
INICIO
STRING s1, s2, str
NUMERICO n1, n2, n
VECTOR v
MATRIZ m
// VERSION STRING
s1 = "-UNO-"
s2 = "-DOS-"
str = s1 + s2
IMPRIMIR(str, "\n")
INTERCAMBIAR(s1, s2)
str = s1 + s2
IMPRIMIR(str, "\n")
// VERSION NUMERICA
n1 = 111
n2 = 222
IMPRIMIR ("\nn1 = ", n1, " - n2 = ", n2)
INTERCAMBIAR(n1, n2)
IMPRIMIR ("\nn1 = ", n1, " - n2 = ", n2)
// VERSION VECTOR
v = [1,2,3,4,5]
IMPRIMIR ("\nv[0] = ", v[0], " - v[4] = ", v[4])
INTERCAMBIAR(v[0], v[4])
IMPRIMIR ("\nv[0] = ", v[0], " - v[4] = ", v[4])
// VERSION METRIZ
m = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
IMPRIMIR ("\nm[0,0] = ", m[0,0], " - m[0,2] = ", m[0,2])
INTERCAMBIAR(m[0,0], m[0,2])
IMPRIMIR ("\nm[0,0] = ", m[0,0], " - m[0,2] = ", m[0,2])
FINAL