Mickey Mathieson a écrit :
>>
>> 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;
>> }
>>
>>
>>     
>
> 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);
> }
>   

Mine wins, she twice must fast ( or more exactly twice less slow)

In fact, you just have to count the number of calls for each functions.
Your will made strlen(str) calles since you decrement count by 1 each time
Mine will made strlen(str)/2 calles since I increment the beginning by 1 
and decrement the end by 1.
(at least on the computer I have here)

David

Reply via email to