Recursion for Data Structure in C programming


          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.

                                     -----;<------------address of this instruction is stored in STACK
                   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.


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites