[GAP Forum] Advise on data structure

Robert Morse rm43 at evansville.edu
Fri Sep 14 22:18:47 BST 2012


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



More information about the Forum mailing list