How do I write an algorithm that finds the m smallest numbers in a list of n numbers?

How do I write an algorithm that finds the m smallest numbers in a list of n numbers?

> Hi all,

> How do I write an algorithm that finds the m smallest numbers in a list
> of n numbers?

Sort them and choose first n elements (or last - depend what sort order
you choose). There is library function for sorting altough I don't
remember the details so you must search help.

Quote:

> Sk

With regards

How do I write an algorithm that finds the m smallest numbers in a list of n numbers?

Hi,

Sorry , I misspelled .

..... in a list of n numbers... ---> ..... in a ARRAY of n numbers...

But Could you be a little more specific ?
Any source code?

I am a algorithm-beginner.

Sungkwan

> > Hi all,

> > How do I write an algorithm that finds the m smallest numbers in a list
> > of n numbers?

> Sort them and choose first n elements (or last - depend what sort order
> you choose). There is library function for sorting altough I don't
> remember the details so you must search help.

> > Sk

> With regards

How do I write an algorithm that finds the m smallest numbers in a list of n numbers?

Quote:> How do I write an algorithm that finds the m smallest numbers in a
list
> of n numbers?

You can store the numbers in a vector, run the sort algorithm on them
and then take the first m numbers. (vector and sort are part of the
standard library.)

Greg

--
----------------------------------------------------------------------
----------------------------------------
Greg Reese                              Senior Engineer
Qualia Computing, Inc.                  (937) 431-1464 x243
2372 Lakeview Drive, Suite G            (937) 431-1465 FAX

How do I write an algorithm that finds the m smallest numbers in a list of n numbers?

Hi all,

How do I write an algorithm that finds the m smallest numbers in a list
of n numbers?

Sk

How do I write an algorithm that finds both the smallest and largest
numbers in a list of n numbers. Try to find a method that does at most
about 1.5n comparisons of array items?

Could you help me?