I would try the for each approach.
int maxSpeed = 0;
car tempCar;
for each [car currentCar] in [Array enumerator]
if currentCar.brand.equals(@"Ferrari")
{
if ( currentCar.MaxSpeed > maxSpeed )
{
tempCar = currentCar;
}
maxSpeed = car.MaxSpeed;
}
next
tempCar should be your car.
This is the simple approach.
If you'd like, try quick sorting the array by car brand and then optimizing
your itteration. This has a potential of a complex way.
- Moty -
"matthias s." <postamt[theat]emvoid[thedot]de> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
hi,
as a self-taught programmer I've got little clue about coding patterns and
general algorithms. so I'm asking here hoping to improve my skills:
I've got a large array of objects, say Car(s) where a Car has got a
MaxSpeed
and Brand property. How would I go most effectively to search the array
for
the car with a Brand equal to 'Ferrari' and the highest MaxSpeed?
It's not that I couldn't code it, but with your help, I probably could
code
it cleaner/faster.
Thanks for your time!
/matthias