Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Recursion

Programming


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-02-2008   -   Original Discussion by joshighanshyam
joshighanshyam's Unix or Linux Image
joshighanshyam joshighanshyam is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 16 February 2010, 1:17 PM EST
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Recursion

I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language.
Sponsored Links
    #2  
Old Unix and Linux 12-02-2008   -   Original Discussion by joshighanshyam
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 8 February 2016, 5:12 PM EST
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 14 Times in 14 Posts
Quote:
Originally Posted by joshighanshyam View Post
I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language.
Is there any reason you are not taking the iterative approach ?
Sponsored Links
    #3  
Old Unix and Linux 12-02-2008   -   Original Discussion by joshighanshyam
otheus's Unix or Linux Image
otheus otheus is offline Forum Advisor  
Smartass
 
Join Date: Feb 2007
Last Activity: 6 September 2017, 5:43 AM EDT
Location: Innsbruck, Austria
Posts: 2,157
Thanks: 12
Thanked 51 Times in 48 Posts
You've been around long enough not to post homework questions, so I'll answer: use setjmp() and longjmp(). Basically, the first call saves the current stack configuration (stack pointer, parent caller address, etc). The second call restores that stack configuration. So you might have some code like this:


Code:
#include <setjmp.h>
int found = 0;
jmp_buf origin; 
main() {
  setjmp(&origin);
  if (found == 0) 
     recursive_call();
}

recursive_call() {

   /* HERE: set found to 1 at some point */
   /* then... */
   if (found == 0) 
      recursive_call();
   else 
      longjmp( &origin );
}

    #4  
Old Unix and Linux 12-03-2008   -   Original Discussion by joshighanshyam
esther.david6's Unix or Linux Image
esther.david6 esther.david6 is offline
Banned
 
Join Date: Nov 2008
Last Activity: 30 December 2008, 7:51 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
what is recursive?

A procedure that is applied once, and then applied to the result of that application, and so on. A recursive definition defines the result of some operation for 0, and then the result for any number n + 1 in terms of the result for n; thus the operation becomes defined for all numbers (the notion may be extended to describe the same process on any well-ordered set).
Sponsored Links
    #5  
Old Unix and Linux 12-03-2008   -   Original Discussion by joshighanshyam
otheus's Unix or Linux Image
otheus otheus is offline Forum Advisor  
Smartass
 
Join Date: Feb 2007
Last Activity: 6 September 2017, 5:43 AM EDT
Location: Innsbruck, Austria
Posts: 2,157
Thanks: 12
Thanked 51 Times in 48 Posts
Esther/Daid, I don't think the user wants to know WHAT a recursive procedure is. He wants to know how to exit the procedure while skipping all the returns and function clean-up.
Sponsored Links
    #6  
Old Unix and Linux 12-03-2008   -   Original Discussion by joshighanshyam
joshighanshyam's Unix or Linux Image
joshighanshyam joshighanshyam is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 16 February 2010, 1:17 PM EST
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks you all for your valuable Feedbacks
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script recursion superpointer Shell Programming and Scripting 6 02-12-2011 08:24 PM
C Recursion (explain) seede Programming 5 04-26-2010 08:30 PM
KSH: recursion into subdirectories? Wotan31 Shell Programming and Scripting 2 09-24-2008 03:49 PM
Help Help Help in recursion murtaza Shell Programming and Scripting 6 03-29-2007 10:26 AM
recursion gsjf Shell Programming and Scripting 1 08-26-2002 12:22 AM



All times are GMT -4. The time now is 11:52 PM.