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

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Copy directory withOUT recursion chebarbudo UNIX for Beginners Questions & Answers 7 07-25-2018 12:19 PM
BIND 9, disable recursion snchaudhari2 Solaris 0 03-13-2018 12:42 AM
Bash variable recursion yifangt Shell Programming and Scripting 7 08-08-2013 09:54 PM
Recursion list for rm -R in find port43 UNIX for Advanced & Expert Users 5 06-27-2013 10:15 PM
Recursion in a bash script mistsong1 UNIX for Dummies Questions & Answers 6 04-25-2013 05:29 PM
script recursion superpointer Shell Programming and Scripting 6 02-12-2011 09:24 PM
C Recursion (explain) seede Programming 5 04-26-2010 09:30 PM
recursion script problem mac4rfree Shell Programming and Scripting 3 07-21-2009 08:15 AM
KSH: recursion into subdirectories? Wotan31 Shell Programming and Scripting 2 09-24-2008 04:49 PM
How to remove old files without recursion? nir_s Shell Programming and Scripting 5 04-27-2008 11:43 AM
Help Help Help in recursion murtaza Shell Programming and Scripting 6 03-29-2007 11:26 AM
A Question On Recursion In Ksh marlonus999 Shell Programming and Scripting 1 01-11-2007 07:09 AM
allow recursion on dns server? xnightcrawl UNIX for Advanced & Expert Users 1 03-29-2006 10:36 AM
recursion too deep swamy455 Shell Programming and Scripting 3 07-18-2005 04:18 PM
recursion gsjf Shell Programming and Scripting 1 08-26-2002 01:22 AM
All times are GMT -4. The time now is 06:55 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.