Examples of Recursion
Problems
Problem : Write the reverse() function recursively. This function takes a string and the length of the string as arguments and returns the same string with its characters in the reverse order.
Problem : Challenge: You're given a piece of memory containing characters divided into two sections, section a and section b, that follow each other in memory, b after a. You are also supplied with the lengths of a and b. Write a function that uses your reverse() function from above to swap the two sections such that the a section follows the b section. This does not require recursion.
Problem : Write a function count_spaces(char *s) that counts the number of whitespace characters that appear in a string. Characters are whitespace as defined by the isspace() function in the ctype library. Write this function recursively.
Problem : Why would a programmer most likely not use recursion for an implementation of the string library?
Problem : A palindrome is a sequence of characters or numbers that looks the same forwards and backwards. For example, "Madam, I'm Adam" is a palindrome because it is spelled the same reading it from front to back as from back to front. The number 12321 is a numerical palindrome. Write a function that takes a string and its length as arguments and recursively determines whether the string is a palindrome: int ispalindrome(char *s, int len);
Problem : Write a recursive function void replace(char *s, char from, char to); that changes all occurrences of from in s to to. For example, if s were "steve", and from == 'e' and to == 'a', s would become "stava".





