Difference: HandsOnRecursion ( vs. 1)

Revision 12017-05-02 - JimSkon

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="Spring2017"

Recursion

In this activity we will write and test a simple recursive function.

Consider:

string str = "Kenyon College";

We can define the reverse of a string:

rev(str) = str  if str.length() <= 1
= str[str.length()-1] + rev(str.substr(1,str.length()-2) + str[0];

Why is this right?

Can we write and test this in a function?

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback