Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to sort an array(instead arr.sort() method).

how can we found first max or second max programatically.

Regards
James
Posted
Comments
Ed Nutting 18-May-12 7:50am    
Sorry your question is unclear to me. What do you mean "first max" or "second max"? What do you mean by "max"? "Max" what exactly? Maximum value or maximum sort speed? Also, if you're looking for sorting algorithms, just type "Sorting Algorithms" or "C~ Sorting Algorithms" into Google and you will find a lot of very helpful information which will answer your questions.

Thanks,
Ed

Use LINQ.

C#
list = list.OrderByDescending(x => x).toList();


Then write a method to get a distinct list such as:

C#
public static IEnumerable<TSource> DistinctBy<TSource,TKey>
    (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
    HashSet<tkey> seenKeys = new HashSet<tkey>();
    foreach (TSource element in source)
    {
        if (seenKeys.Add(keySelector(element)))
        {
            yield return element;
        }
    }
}


Then the first max will be list[0], the second will be list[1] e.t.c.
 
Share this answer
 
v4
http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b[^]

Look under the Aggregate Operators column
 
Share this answer
 
by using sorting techniques u will sort an array elements
ex:Sorting Algorithms Codes in C#.NET[^] quick sort


see this link it may help you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900