View Single Post
  #8 (permalink)  
Old 10-05-2006, 12:56 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 4,092
Last Blog:
Why Learn Data Structu...
Credits: 28
Rep Power: 45
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

You have most of what you need for doing a reverse.
The basic idea of recursion is to break a task into many smaller steps that are identical. For instance, if you want to compute a factorial (5! = 5*4*3*2*1), one way to do it is to say n! = n*(n-1)!, and note that 0!=1.

For reversing your string, just note that MyString.rev() = MyString.tail().rev()+MyString.head(), and a single character string is its own reverse.

Once you have part 1 done, part 2 is trivial. For testing the prefix, just test the heads and tails of the strings.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Reply With Quote