# How to sort Matrix

I am on permutation project, and I have trouble with my result, the sequence of my result is not same with Permutations in Mathematica here the code

x[l_, elmn_] :=   Join[{h[l, elmn][[elmn - 2]]},
Reverse[ {h[l, elmn][[elmn - 1]] , h[l, elmn] [[elmn]]}]];

Table[{h[l, 3], x[l, 3]}, {l, 3}]


{{{2, 3, 1}, {2, 1, 3}}, {{3, 1, 2}, {3, 2, 1}}, {{1, 2, 3}, {1, 3, 2}}}

But the result on Mathematica Permtations is

Permutations[{1, 2, 3}]


{{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}}

I want to sort it to make it exactly same like Permutations

• Is the intended question here that you want to Sort the lists at the bottom level in the input array? You say "short", but the result shown looks sorted. If that's so, do you want to preserve the structure of the original array? Commented Apr 30, 2018 at 20:34
• yes, i want the matriks array still on their position, like Permutations[{1,2,3,4,5}]. i am already have the matriks. but their posistion its so random Commented Apr 30, 2018 at 20:40
• Can you check the brackets in the first line of code? With list = {{2, 3, 4, 5, 1}, {2, 1, 5, 4, 3}, {3, 2, 1, 5, 4}}, Sort /@ list does what I understand you want. Commented Apr 30, 2018 at 21:14
• That structure also more closely matches what we would expect Permutations[{1, 2, 3, 4, 5}] to look like, and that was mentioned in the question. Commented Apr 30, 2018 at 21:28

list = {{{2, 3, 1}, {2, 1, 3}}, {{3, 1, 2}, {3, 2, 1}}, {{1, 2, 3}, {1, 3, 2}}};