-->

Tuesday, March 11, 2014

Recursion for Data Structure in C programming

 Recursion for Data Structure in C programming

Recursion:


          Recursion is another good example of programming field where STACK is used. Recursion is an art of programming or a technique in programming in which the subprogram calls itself. In programming usually when a subprogram is written it is called in main program. Using a statement in the main program can do a call to the subprogram. If a call statement of the subprogram is used within the definition of the same subprogram then it is termed as recursion.
                                        Whenever a function (in case of C the subprogram is function) call is made in main program the control transfers to the function, the function is executed and control transfers back to the calling point. Note here that the internal STACK is used to store the address of the next instruction that is to be execution completes.

                                   main()
                                  {
                                     -----;
                                     fun();
                                     -----;<------------address of this instruction is stored in STACK
                                  }
                                   fun()
                                   {
                                      ----:
                                    }
                   The recursion can be used to solve certain problems where the problems have base condition. When the base condition is satisfied the call should terminate otherwise a call is made again with changed value. Means recursion is used only in those cases when the same set of statements are to be executed again and again with changed value and that changed value reaches to base condition the recursive call should terminate.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved