Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7727 > unrolled thread

Custom sorting via ordering list

Started byChris Young <cy56@comcast.net>
First post2012-01-11 09:28 +0000
Last post2012-01-11 09:28 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Custom sorting via ordering list Chris Young <cy56@comcast.net> - 2012-01-11 09:28 +0000

#7727 — Custom sorting via ordering list

FromChris Young <cy56@comcast.net>
Date2012-01-11 09:28 +0000
SubjectCustom sorting via ordering list
Message-ID<jejko2$bch$1@smc.vnet.net>
Don't really need the matrix I had in my previous post, just the sort 
specification. All the upper-triangular matrix did was to ensure there 
was a less-than-or-equal relation, and we're taking care of that by 
simply testing pairs of elements to make sure they're in the same 
left-to-right order as they are in the "sorted" list we specify in the 
in_order function.

In[839]:= in\[HorizontalLine]order2[e1_, e2_] :=
 Module[
  {sorted},
  sorted = {1, 2, a, b, A, B};

  Position[sorted, e1][[1, 1]] <= Position[sorted, e2][[1, 1]]
  ]


In[840]:= Sort[list, {e1, e2} \[Function] in\[HorizontalLine]order2[e1, e2]]

Out[840]= {1, 2, a, b, A, B}


In[841]:= Sort[{B, a, 1, b, b, 1}, {e1, e2} \[Function]
  in\[HorizontalLine]order2[e1, e2]]

Out[841]= {1, 1, a, b, b, B}

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web