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?

Post by Jacek Marche » Fri, 11 Sep 1998 04:00:00




> 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:

> Thanks in advanced.

> Sk

With regards
 
 
 

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

Post by Sungkwan Par » Sat, 12 Sep 1998 04:00:00


Hi,

Thanks for your Response.

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.

Thanks in advance,

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.

> > Thanks in advanced.

> > Sk

> With regards


 
 
 

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

Post by Greg Rees » Sat, 12 Sep 1998 04:00:00


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?

Post by Sungkwan Par » Sun, 13 Sep 1998 04:00:00


Hi all,

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

Thanks in advanced.

Sk