little_cat()

Oct 31, 2007 20:58


/* And then Little Cat A * Took the hat off HIS head. * "It is good I have some one * To help ME," he said. * "This is Little Cat B. * And I keep him about, * And when I need help * Then I let him come out." * And then B said, * "I think we need Little Cat C." * -- "The Cat in the Hat Comes Back" Dr. Seuss */ void little_cat( const char letter ) { if ( letter == 'Z' ) voom(); else little_cat( letter + 1 ); } If I ever end up as a tenured professor teaching first year CS, I'm going to put "The Cat in the Hat Comes Back" on the recommend reading list. I'd noticed a couple of weeks ago that the "Little Cats" stored under the Cat's hat were an excellent example of recursion, with Little Cat Z using Voom providing the base case. Also that it's tail recursive (as it should be when cats are involved). This morning while reading it once more to Daniel I noticed that the first half of the book illustrates iteration, too, with the cat transferring the spot from place to place.
Previous post Next post
Up