I have been trying to write a program to sort a list and cannot seem to get it right…:
Triliste[a_] :=
Module[{min, x, i, j}, For[i = 1, i < Length[a], min := i;
For[j = i + 1, j <= Length[a],
If[a[[j]] < a[[min]], min := j]]; x,
If[min! i, x := a[[i]]; a[[i]] = a[[min]]; a[[min]] := x]]
] a;
what is wrong?
nma
(Nasser M. Abbasi)
2
I noticed you write
i < Length
But Length is a function, that needs an argument. see ?Length
aibobrofff
(Andrei Bobrov)
4
Please try this is code:
Triliste[a_] :=
Module[{x = a}, m = Length[a]; For[i = 1, i < m, i++,For[j = i + 1, j <= m, j++, If[x[[i]] > x[[j]], x[[{i, j}]] = x[[{j, i}]]]]]; x]