Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coding puzzle (4)
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00665368
Message ID:
00665442
Vues:
28
Right. I'm still thinking on the problem (though I should work :)

The idea would be to check arr[k]*2 with X and arr[k] with X, there k is the middle number.



>That's not really elogant...
>
>By k, I assume you are talking about k=alen(arr) ?
>
>You do find the maxium value in log time.
>
>But I think it might be better, just to:
>
>max_element = 0
>max_index = 0
>for k = alen(arr) to 1 step -1
> if X >= arr(k)
> max_element = arr(k)
>
> endif
>endfor
>
>>test = arr[int(k/2)]
>>if X < test && We don't need to check the rest of the array
>> test = arr[int(k/4))
>> if X < test && we don't need to check 3/4 of the array
>> ...
>> endif
>>endif
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform