recursion

self referential struct definition?

Hi I haven't been writing C for very long, and so I'm not sure about how I should go about doing these sorts of recursive things... I would like each cell to contain another cell, but I get an error along the lines of "field 'child' has incomplete type". What's up? typedef struct Cell { int isParent; Cell child; } Cell; Thanks, ...

Automatically refactor a loop into a recursive method?

Do you know a tool that automatically refactors a method with a single loop into a recursive method, preferably in Java? This is for teaching purposes. ...

Combining recursive iterator results: children with parents

I'm trying to iterate over a directory which contains loads of PHP files, and detect what classes are defined in each file. Consider the following: $php_files_and_content = new PhpFileAndContentIterator($dir); foreach($php_files_and_content as $filepath => $sourceCode) { // echo $filepath, $sourceCode } The above $php_files_and_c...

Hierarchical recursion menu with PHP/MySQL

This should (hopefully) be a pretty easy question for some of you to answer. I have a working Recursive menu from a mySQL database, now my main problem is: What is the best way to create the URL? I would prefer to bring in the title of each row like /eggs/milk/bacon/. Eggs being level 0 like: eggs-0, milk-1, bacon-2. Any ideas on ho...

How to get lowest, common parent for 2 rows in recursive table (SQL)

Let's say that we have we have a table with the classic 'manager id' recursive relationship: Users user_id int manager_id int (refers to user_id) If you randomly select 2 rows in the table- or 2 nodes- how do you find the lowest level, common ancestor? My platform is SQL Server 2005 (Transact-SQL) but any ANSI compliant SQL will ...

Linearly recursive list-difference function in Common Lisp.

I was going through this tutorial for fun, and got stuck on the very last thing he says, "Exercise: Give a linearly recursive implementation of union and difference." (for a list) Union, no sweat. Difference, sweat. An attempt looks like this. . . (defun list-diff (L1 L2) (cond ((null L1) L2) ((null (member (first L1) L2...

Using Recursion in C#

Are there any general rules when using recursion on how to avoid stackoverflows? ...

Is it possible to remove recursion from this function?

I have been playing with this a while, and just cannot see an obvious solution. I want to remove the recursion from the XinY_Go function. def XinY_Go(x,y,index,slots): if (y - index) == 1: slots[index] = x print slots slots[index] = 0 return for i in range(x+1): slots[index] = x-i XinY_Go(x-(x-i...

Iterative version of Python's deepcopy

Is there an existing implementation of an iterative version of deepcopy for Python 2.5.2? The deepcopy method available from the copy module is recursive and fails on large trees. I am not in a position where we can safely increase the stack limit at runtime. EDIT I did track this down: http://code.activestate.com/recipes/302535/ I h...

Is it possible to speed up a recursive file scan in PHP?

I've been trying to replicate Gnu Find ("find .") in PHP, but it seems impossible to get even close to its speed. The PHP implementations use at least twice the time of Find. Are there faster ways of doing this with PHP? EDIT: I added a code example using the SPL implementation -- its performance is equal to the iterative approach ED...

Recursive functions within OCaml objects

I am trying to figure out recursion for OCaml in the context of an object's method. I have tried the following code but can't seem to get it to compile. class foo = object (self) method loopTest = let rec doIt x = Printf.printf "%d\n" x; if x>1 then doIt (x+1) end;; How do I create a recursive function of this sort within a m...

What is the best way to recursively copy contents in C#?

What is the best way to recursively copy a folder's content into another folder using C# and ASP.NET? ...

Need help on making the recursive parser using pyparsing

I am trying the python pyparsing for parsing. I got stuck up while making the recursive parser. Let me explain the problem I want to make the Cartesian product of the elements. The syntax is cross({elements },{element}) I put in more specific way cross({a},{c1}) or cross({a,b},{c1}) or cross({a,b,c,d},{c1}) or So the general f...

A good bank of solved recursion problems in C/C++/Java/C#

I saw this question, but the answers there are not very relevant. A friend needs a bank of solved recursion problems to help him study for a test tomorrow. He learned the issue theoretically, but is having problems grasping how to actually solve recursion problems. Do you know a good source of solved recursion problems (preferably in C,...

Recursively counting files with PHP

Simple question for a newb and my Google-Fu is failing me. Using PHP, how can you count the number of files in a given directory, including any sub-directories (and any sub-directories they might have, etc.)? e.g. if directory structure looks like this: /Dir_A/ /Dir_A/File1.blah /Dir_A/Dir_B/ /Dir_A/Dir_B/File2.blah /Dir_A/Dir_...

Delete child items recursively in Sitecore CMS.NET

I have the following structure in my Sitecore media library images/department/sub-department/product/ And I want to delete all of the images in code a department at a time. At the moment I have Item[] items = database.SelectItems("/sitecore/media library/images/department1//*"); Sitecore.Data.Engines.DataEngine engine...

Recursion leading to out of memory

I have a RAM of 2 GB. We have a application which performs Export/Import operations. We have a recursive function which has one local variable of type Set which keeps on getting populated every iteration. This Set keeps growing and at one point we run out of memory. Is there any alternative data structure which can optimally use the mem...

Haskell: recursion with array arguments

Disclaimer: I'm new to Haskell and I don't remember a lot about FP from university, so there may be more than one or two errors in my code. This is also my code for Euler Problem 3. I'm trying to recursively call a function with two arrays as arguments and an array as a result. The goal: assume n is 10 for this question create a lis...

G++ Compiler won't allow recursion?

I have created a very simple program that uses recursion. I'm using the g++ compiler. I can compile it, but when I try to run it I get an error message that says SEGMENTATION FAULT. Here's my code: #include <iostream.h> using namespace std; int Recurse(int); int main(int argc, char *argv[]) { Recurse(10); cout << endl;...

Bash: Recursively adding subdirectories to the path

... How do you do it? My code/ directory at work is organized in folders and subfolders and subsubfolders, all of which (at least in theory) contain scripts or programs I want to run on a regular basis. Its turning my otherwise picturesque .bashrc into an eyesore! Thanks! ...