SortPermutation - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

StringTools

 SortPermutation
 return a permutation that sorts a list of strings

 Calling Sequence SortPermutation( los )

Parameters

 los - list(string); a list of strings

Description

 • The SortPermutation( los ) command returns a permutation $p$ that sorts the list los, that is, for which $\left[\mathrm{seq}\right]\left({\mathrm{los}}_{{p}_{i}},i=1..\mathrm{nops}\left(\mathrm{los}\right)\right)$ is equal to $\mathrm{sort}\left(\mathrm{los}\right)$. The sorting order is lexicographic.
 • The permutation returned by SortPermutation is represented as a list of the positive integers from $1$ to $\mathrm{nops}\left(\mathrm{los}\right)$.
 • Note that an empty list, which is vacuously a permutation, is returned if the input list los is empty.
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $L≔\left["b","c","a"\right]:$
 > $p≔\mathrm{SortPermutation}\left(L\right)$
 ${p}{≔}\left[{3}{,}{1}{,}{2}\right]$ (1)
 > $\mathrm{type}\left(p,'\mathrm{permlist}'\right)$
 ${\mathrm{true}}$ (2)
 > $\left[\mathrm{seq}\right]\left({L}_{{p}_{i}},i=1..3\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}\right]$ (3)
 > $\mathrm{sort}\left(L\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}\right]$ (4)
 > $\mathrm{SortPermutation}\left(\left[\right]\right)$
 $\left[\right]$ (5)