Reverse string output--recursion

Source: Internet
Author: User

Speaking of recursion, it's easy to think of n!. , the Fibonacci sequence (the number of rabbits), of course, is a very good understanding of the problem. Personally, it is the Hanoi and string inverse output that best reflects the recursion essence. Hanoi tower problem only need to think one step, other problems to the computer, it is very good to prove that recursion is lazy people dedicated algorithm. This alone is sufficient to conceal the drawback of inefficient recursion. As we all know, recursion is the process by which a function calls itself. In the C language, the function calls itself and calls other functions without a bit of distinction. is to save the scene, function calls, restore the site process, which is popular, in our professional terminology, the essence of recursion is into the stack and the process of the stack. Explained here, recursive implementation of string output problem is very good solution. Directly on the code, understand the problem, grasp the whole into the stack of the nature of the stack is good.

Code

  4* Filename: A. C5*6*Description:7*8* Version:1.0  9*created:2014 December 29 09:02 57 secondsTen*Revision:none One*COMPILER:GCC A* -*author:3me (), -*Organization: the* -* ===================================================================================== -*/ -#include <stdlib.h> +#include <stdio.h> - /** = = FUNCTION ====================================================================== * NAME:PRI NT $ * description:24 * ===================================================================================== 25 /c5>*/  -     void  -print () - {  in     intC; -     if((c = GetChar ())! =-1 )  toprint (); +     Else  -printf"\ n");  the     if(c! =-1 )  *printf"%c", c);  $     return; Panax Notoginseng}/*-----End of function Print-----*/  - /** = = = FUNCTION ====================================================================== * Name:mai n * description:42 * ===================================================================================== 43 
    */  -     int  $Main (intargcChar*argv[]) $ {  -print (); -   the     returnexit_success; -}/*----------End of function main----------*/ Wuyi                     

Reverse string output--recursion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.