--- David <[EMAIL PROTECTED]> wrote:
> 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
>
>
But how about the prcessing each function does - your
makes 1/2 the calls but how about while in the
function itself.
Your is faster if just counting the number of time
the recursion function is called. But how about total
processing time.
Mickey
____________________________________________________________________________________
No need to miss a message. Get email on-the-go
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail