canShrink()

bool canShrink(const string& word, const Lexicon& english)  {
   if(word.empty()) {
      words.push("");
      return true;
   }

   for(int i=0; i<word.size(); i++) {
      if(canShrink(word, english)) {
         words.push(word);
         return true;
      }
   }
}

Recursion Lecture
Tail recursion - much more efficient

int fib(int n) {
   return fib(n,0,1);
}

int fib(int n, int base0, int base1)  {
   if(n==0) return base0;
   if(n==1) return base1;
   return fib(n-1, base1, base0+1);
}

   Login to remove ads X
Feedback | How-To