RE: highest value in a an array
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Tue, 3 Apr 2007 22:19:25 +0100
Wibberlet <Wibberlet@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Basically you will need to sort the array and then choose the last element
(assuming you have sorted it in lowest to highest order).
Well, that's one way to do it. Its complexity is O(n log n) however,
whereas just finding the maximal value only needs to be O(n).
You just go through the array, remembering the current highest value:
int max = int.MinValue;
foreach (int value in integerArray)
{
if (value > max)
{
max = value;
}
}
LINQ will make all of this rather easier.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Prev by Date: Re: dictionary (hash table) with two values?
- Next by Date: Re: Not Initializing Variables : Performance impact
- Previous by thread: Re: Process.ExitCode fails
- Next by thread: Re: Base Method Calling Child Methods
- Index(es):
Relevant Pages
|