Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Argument starter - The roots of all evil
Message
De
12/09/2004 14:08:33
Walter Meester
HoogkarspelPays-Bas
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00938079
Message ID:
00941472
Vues:
49
Hi george,

>I don't know about "...thread recursive" here< s >, but some of the basic algorithms I have seen do implement this recursively. My problem with that is that it not only tends to "cloud" things, but doesn't perform as well because of the recursive calls.

A basic example how to this recursively is the following.
FUNCTION SearchArray2(aArray, cSearchValue, nStart, nEnd, nIndex)

RETURN IIF(nStart > nEnd, 0, ;
	IIF(aArray[nIndex] > cSearchValue, SearchArray2(@aArray, @cSearchValue, @nStart, nIndex - 1, INT((nStart + nIndex -1)/2)),;
	IIF(aArray[nIndex] < cSearchValue, SearchArray2(@aArray, @cSearchValue, nIndex+1, @nEnd, INT((nIndex+1+nEnd)/2)), nIndex)))
And indeed it clouds things and because of the stack overhead in calling functions causes this algorithm to be significantly slower than a DO WHILE or FOR NEXT solution.

However some circumstances do call for a recursive solution, like the programming challenge calvin hsia did attend to to solve a phone number - words problem. Just when using private or local variables that can be totally hidden from the calling level and reusing the same code in which the same variable name is used. Not using recursivism would just complicate things as calvins code did demonstrate.

Walter,
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform