I want to sort a list like below.Without using the build-in function so I tried this:
sort[n_] :=
Module[{n0 = n, i, j},
Do[Do[If[n[[j - 1]] >
n[[j]], {n[[j - 1]], n[[j]]} = {n[[j]], n[[j - 1]]}],
{j, Length[n], i, -1}];
, {i, 1, Length[n] - 1}]; n]
l = {2, 1, 1, 10, 9, 8, 1};sort[l]
But it seem my code is not correct.Can Anyone help me to figure out this. Any hints or solution will be appreciated.
Sort
? Is this homework? Also you should use a semicolon;
instead of a comma,
before callingsort
. $\endgroup$ – ktm Dec 29 '18 at 19:41