Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

A custom String Class

string

  • Please log in to reply
15 replies to this topic

#13 hoser2001

hoser2001

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 170 posts

Posted 08 October 2006 - 02:27 PM

Ok i figured this one out, the problme was in my + operator.
I was using a for loop to make the copy when all I should have done was
strcpy. Problem solved.

But I am still confused as to how the recursion works, I know it works because I can do it, but I don't understand the steps involved. COuld someone please show visually what is happening in my reverse function:?

if (string.head() == '\0')
return string;
return reverse(string.tail()) + string.head();
  • 0

#14 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 October 2006 - 09:25 AM

Here's what's happening: Suppose your string is "Hello There\0".
call 1: String.reverse() chops it into 'H' and "ello There\0", with the 'H' waiting to append and "ello There\0" waiting to be reversed.
call 2: String.reverse() chops it into 'e' and "llo There\0", with the 'e' waiting to append and "llo There\0" waiting to be reversed.
call 3: String.reverse() chops it into 'l' and "lo There\0", with the 'l' waiting to append and "lo There\0" waiting to be reversed.

.
.
.
call 11: String.reverse() chops it into 'e' and "\0", with the 'e' waiting to append and the "\0" waiting to be reversed.
call 12: String.reverse() spits back "\0".
finish call 11: String.reverse spits back "\0e".
.
.
.

finish call 3: String.reverse spits back "\0erehT oll"
finish call 2: String.reverse spits back "\0erehT olle"
finish call 1: String.reverse spits back "\0erehT olleH"
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#15 hoser2001

hoser2001

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 170 posts

Posted 09 October 2006 - 01:27 PM

oooooooooooooo

you make much more sense then my prof does.
thanks a lot!
  • 0

#16 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 October 2006 - 03:05 PM

It comes from teaching algebra to math-phobes.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download