Re: Fastest way to read numbers in ascending order from array of integ



In article <6E363210-0FD3-45A3-A2DC-CE30F8BA18B2@xxxxxxxxxxxxx>,
Srini@xxxxxxxxxxxxxxxxxxxxxxxxx says...

[ ... ]

Wondering what would be the fastest way to find the numbers(samllest one
first, the next big one next, so on until all the numbers in the array are
read) in their ascending order.

The obvious way would be to sort the array (e.g. std::sort). Less
obvious would be to use a priority_queue. At a guess, std::sort is
probably closer to what you want.

Once all the numbers are read, the array will be written with another set of
numbers. This reading(in ascending order) and writing continues couple of
thousand times a second.

Okay. Is this really a single stream of data, or is there a good reason
each of these has to be separate from the others? If you're trying to
implement something like a merge sort, you're generally better off not
keeping the initial runs separate from each other.

Also the procedure should not only be fast but also efficient in CPU cycles.
Does any one have any ideas? Should I go to assembly code here?

The first real question is how much data you're really going to be
working with -- "three or more numbers" is pretty open, to put it
mildly. If you're really looking at less than (say) 100 each time,
chances it the sort you use hardly matters at all -- you'll be able to
sort faster than you can read/write the data. If you're looking at a
million items each time, keeping up may take a lot more work.

--
Later,
Jerry.

The universe is a figment of its own imagination.
.



Relevant Pages

  • Re: sorting int[] in descending order
    ... I know that one can sort in ascending order and reverse the array. ...
    (comp.lang.java.help)
  • Re: How to sort a list in VAX BASIC
    ... > I have a VAX Basic program that loads data into a one dimensional ... After I load the data into the array, ... > data in the list (ascending order) before reading it and handling it ... I thought writing a sort was still programming 101. ...
    (comp.os.vms)
  • Re: sorting database search results
    ... ascending order. ... can anyone please help with a sort string? ...     foreach{ ... // set the array identifier as the contact ID to stop duplicate ...
    (php.general)
  • sort 2D array
    ... Here is a bubble sort for an array in ascending order I've taken from J-Walk ... Dim lTemp As Single ...
    (microsoft.public.excel.programming)
  • Re: sorting int[] in descending order
    ... I know that one can sort in ascending order and reverse the array. ...
    (comp.lang.java.help)