[GAP Forum] Advise on data structure

Igor Korepanov paloff at ya.ru
Sat Sep 15 09:03:39 BST 2012


Interesting command, by the way! Here is what I tried:

gap> o := function(x,y) return true; end;;
gap> a := [3,2,5,4,7,6,9,8,0,1];; Sort(a,o); a;
[ 1, 0, 8, 9, 6, 7, 4, 5, 2, 3 ]
gap>  :D

Igor


15.09.2012, 01:18, "Robert Morse" <rm43 at evansville.edu>:
> The sort command allows for user defined orderings.
>
> #Here is a user defined ordering
> ord := function(x,y) return x[1]<=y[1]; end;
>
> # A list
> lst := [[3,2,1],[2,5,1]];;
>
> # Sort using the user defined ordering
> Sort(lst,ord);
>
> # See the result
> lst;
> #[ [ 2, 5, 1 ], [ 3, 2, 1 ] ]
>
> Sort([[3,2],1,[2,5,1], ord);
>
> Robert F. Morse
>
> On Fri, Sep 14, 2012 at 3:45 PM, Ha T. Lam <hatlam at gmail.com> wrote:
>
>>  Dear GAP forum,
>>
>>  I have objects which are lists of 3 elements. I want to keep them sorted
>>  according to the first elements on the lists, which are integers, but I'm
>>  not sure what to use as the data structure so that I can make use of GAP's
>>  sorting algorithm. Is there anyway to use nested lists in this case? I
>>  looked into Hash, but that only accept non-negative integers.
>>
>>  Do you have any advise?
>>
>>  Best regards,
>>
>>  Ha T. Lam
>>  _______________________________________________
>>  Forum mailing list
>>  Forum at mail.gap-system.org
>>  http://mail.gap-system.org/mailman/listinfo/forum
>
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum



More information about the Forum mailing list