C语言之递归

#include <stdio.h>

void e(int);

int main(void)
{
   int a = 3;
   e(a);

   putchar('\n');
   return 0;
}

void e(int n)
{
   if (n > 0)
   {
      e(--n);
      printf("%d ", n);
      e(--n);
   }
}

e(0), e(-1) -> {}
e(1) -> {e(0), print 0, e(-1)} -> {{}, print 0, {}} -> {print 0}
e(2) -> {e(1), print 1, e(0)} -> {{print 0}, print 1, {}} -> {print 0, 1}
e(3) -> {e(2), print 2, e(1)} -> {{print 0, 1}, print 2, {print 0}} -> {print 0, 1, 2, 0}




posted @ 2012-07-08 19:29  wdliming  阅读(102)  评论(0编辑  收藏  举报