//TRACCIA: dato un vettore di lunghezza n, restituire lo stesso vettore ordinato function A = ordinaVett(A) //lastIndex = length(A) for (i=1:length(A)) [minValue, pos] = min(A(i:length(A))) tmp = A(i) A(i) = minValue A(pos+i-1) = tmp end endfunction //TRACCIA: Scrivere una funzione Scilab che, dati in input due vettori ordinati A e B, non necessariamente // della stessa lunghezza, restituisca un nuovo vettore ordinato C risultano della fusione di // A e B in C function C = fusione(A,B) i = 1 j = 1 k = 1 lengthA = length(A) lengthB = length(B) while (i <= lengthA) & (j <= lengthB) if (A(i) < B(j)) C(k) = A(i) i = i + 1 else C(k) = B(j) j = j + 1 end k = k + 1 end if i > lengthA while j <= lengthB C(k) = B(j) k = k+1 j = j+1 end else while i <= lengthA C(k) = A(i) k = k+1 i = i+1 end end endfunction A = [5 2 7 3 8 9 1] //A = [1 2 3 5 7 8 9] B = [15 5 7 3] //B = [3 5 7 15] disp(A) disp(B) A = ordinaVett(A) B = ordinaVett(B) C = fusione(A,B) disp(A) disp(B) disp(C')