How to sort a vector without using the sort command

I can only use input, length, disp, while loops and if-else

2 comentarios

What have you done so far? What sorting algorithm are you supposed to use?
Rayan Hussaini
Rayan Hussaini el 8 de Dic. de 2015
Editada: Rayan Hussaini el 8 de Dic. de 2015
what I have so far, but it isn't working
A=input('A=');
i=1;
j=1;
while j <= (length(A)-1)
while i <= (length(A)-1);
if A(i)>=A(i+1);
z=A(i);
A(i)=A(i+1);
A(i+1)=z;
i=i+1;
else A(i)=A(i);
A(i+1)=A(i+1);
i=i+1;
end
end
j=j+1;
end
disp(A)

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 8 de Dic. de 2015
The task is not possible under those conditions. In order to sort, you would need to also be able to use indexing, and comparison operators, and (depending how the question was worded) possibly assignment as well.

Categorías

Preguntada:

el 8 de Dic. de 2015

Editada:

el 8 de Dic. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by