clear; clc; % Parar o loop, vetor ordenado parar=1; v=1:10001; % Preenche o vetor com valores aleatórios for x=1:10000 v(x)= rand*10; end opcao=input('1 - Crescente ou 2 - Decrescente: '); while (parar == 1) parar=0; for (x=1:10000) if (opcao == 1) if ( v(x) > v(x+1) ) troca = v(x); v(x) = v(x+1); v(x+1) = troca; parar=1; end else if ( v(x) < v(x+1) ) troca = v(x); v(x) = v(x+1); v(x+1) = troca; parar=1; end %if end % if opcao end % for end % while