Re: sort list



On 19 Sep 2005 08:41:11 -0700, vincent.fayolle@xxxxxxxxx wrote or
quoted :

>I have one list who contains other lists :
>
>
>Like :
>
>myList(
>{"Stephan","GUINVER",16,76},
>{"John","KENEDY",34,45},
>{"ELSA","ARMBRUSTER",8,64}
>}
>
>What is the syntax to sort this list by firstname or lastname or age

I would create an Person object with firstName, Surname, birthDate
(not age which goes stale daily) etc. fields. Then you can store the
objects in any sort of Collection. see
http://mindprod.com/jgloss/collection.html

If you define a Comparable natural order, the various sorted
Collections will keep things in order for you, or you can sort
explicitly an ArrayList or array. You can define an alternate order
with a Comparator.

See http://mindprod.com/jgloss/sort.html
http://mindprod.com/jgloss/comparable.html
http://mindprod.com/jgloss/compartor.html


--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
.



Relevant Pages

  • RE: Incident investigation methodologies
    ... However, what sort of reaction ... Speculation gets you nowhere. ... > malware we encounter. ... > of what makes public lists useful - you can get some ...
    (Incidents)
  • Re: Detailed explanation of how a QuickSort Works
    ... Firstly, if you consider the simple "Bubble Sort" algorithm, it works by running through the entire data set, one item at a time, comparing each item to the previous item and swapping them if they are not already in the correct order. ... by simply running through the entire list just once (and splitting it into two smaller lists) you have cut the sorting time in half. ...
    (microsoft.public.vb.general.discussion)
  • Re: Ordering Products
    ... algorithms. ... lists with constrained item transpositions. ... I think while the built in sort works as a convenience, ... Overall it's about 10 times slower than pythons built in sort for large ...
    (comp.lang.python)
  • Re: Ordering Products
    ... > Kay Schluehr wrote: ... >> It would be interesting to examine some sorting algorithms on factor ... >> lists with constrained item transpositions. ... > I think while the built in sort works as a convenience, ...
    (comp.lang.python)
  • Re: Educated guesses for efficiency?
    ... it is comparatively rare for a program to run too slowly because an algorithm with the wrong big-O analysis was chosen. ... of things tended to be stored in lists). ... built-in sort function. ... Programmers *will* use algorithms with high complexities. ...
    (comp.lang.c)