Re: sorting an array.. need help



namemattersnot@xxxxxxx wrote:
> i've have the following array:
>
> files['name'][1]
> ['size'][1]
> ['time'][1]
> files['name'][2]
> ['size'][2]
> ['mtime'][2]
> ..etc.
>
> how do I sort this array according to "time" index? so that, for
> example, files['name'][0] would give "my_file.txt" that was last
> created?

A little *dirty* trick is to rearrange the array into a new array, where the
time is first entry.
In this case, swap it around so you get
files
['time'][1]
['size'][1]
['name'][1]
When you sort it now, it will be correct as its sorted on first entry =
time.
Then swap it back to the original structure.

See the "smith / johnson/ berger" example at php.net/sort


.



Relevant Pages

  • Re: "Sorting" assignment
    ... And many others prefer to call partition exchange because "quicksort" ... bin B depending on whether it is greater than, ... If the array is already sorted, this means that you end up ... attempt to sort them. ...
    (comp.programming)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)
  • Re: problem in solving this.
    ... element is selected and placed at the end of the array. ... It looks like bubble sort to me. ... One swap per pass. ...
    (comp.lang.fortran)
  • Re: User Defined type()
    ... Swap indices when sorting, not element values. ... keep a separate array of indices and swap them around as you sort ...
    (microsoft.public.vb.general.discussion)
  • A Fast sorting algorithm for almost sorted data
    ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ... public class RunSort implements Comparator ... public static void sort(Comparable a, int start,int end) ...
    (comp.compression)