Home Man
Search
Today's Posts
Register

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

Recursion

Tags
programming, recursion

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 12-02-2008
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.
# 2  
Old 12-02-2008
Quote:
Originally Posted by joshighanshyam
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 ?
# 3  
Old 12-02-2008
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 12-03-2008
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).
# 5  
Old 12-03-2008
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.
# 6  
Old 12-03-2008
Thanks you all for your valuable Feedbacks
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Recursion list for rm -R in find port43 UNIX for Advanced & Expert Users 5 06-27-2013 09:15 PM
Recursion in a bash script mistsong1 UNIX for Dummies Questions & Answers 6 04-25-2013 04:29 PM
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
A Question On Recursion In Ksh marlonus999 Shell Programming and Scripting 1 01-11-2007 06:09 AM
allow recursion on dns server? xnightcrawl UNIX for Advanced & Expert Users 1 03-29-2006 09:36 AM
recursion too deep swamy455 Shell Programming and Scripting 3 07-18-2005 03:18 PM
recursion gsjf Shell Programming and Scripting 1 08-26-2002 12:22 AM


All times are GMT -4. The time now is 07:16 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password