Finding Two least number in array.

How to find the least two numbers in a single dimension array in a single pass (traversing the elements only once)

Questions by ramsoi   answers by ramsoi

Showing Answers 1 - 1 of 1 Answers

amitprasad

  • Mar 21st, 2008
 

It is very simple man. Just do like taht.

#define LEAST_COMPARE(index, least) list[index] < list[least]

for (index = 0;index < 10;index++)
{
    if (LEAST_COMPARE(index,least))
    {
        second_least = least;
        least = index;
    }
}
list is array of elements and lest and second_least gives the index to array.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions