--- David Fleury <[EMAIL PROTECTED]>
wrote:

> 
> 
> > -----Message d'origine-----
> > De : [email protected]
> [mailto:[EMAIL PROTECTED] De la part de
> > Mickey Mathieson
> > Envoyé : vendredi 16 mars 2007 13:35
> > À : [email protected]
> > Objet : Re: [c-prog] Recursion - Reverse String
> Example
> > 
> > 
> 
> It was not clear that you can't change the main
> function declaration
> (convention? Firstly I thought about stdcall, ... )
> Just for fun... RevStr did not change but call a
> better recursive
> function mostly for storing the initial string size.
> 
> 
> char* reverse_r( char*, char* );
> 
> char *RevStr(int count, char *str)
> {
>   return reverse_r( str, str + count - 1 );
> }
> 
> char* reverse_r( char* begin, char* end )
> {
>   if ( end <= begin ) return begin;
>   char c = *end; *end = *begin; *begin = c; //swap
>   reverse_r( begin+1, end-1 );
>   return begin;
> }
> 
> Regards,
> David
> 
>  
> 
> 
> [Non-text portions of this message have been
> removed]
> 
>

Then i could do the same thing with my version. I
wounder which one is faster. I am not familiar with
the program/technique you used to compare the
functions. Can you let me know and/or test them.

Thanks
Mickey

char *RevStrB(int bcount, int count, char *str);

char *RevStr(char *str)
{
         int count = strlen(str);
         return(RevStrB(count, count, str));

}

char *RevStrB(int bcount, int count, char *str)
{
        char Value;

        if (!count) return(str);
        Value = str[count-1];
        RevStrB(bcount, count-1, str);
        str[bcount - count] = Value;
        return(str);
}






 
____________________________________________________________________________________
Don't get soaked.  Take a quick peek at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather

Reply via email to