recursion

Recursive call is corrupting my data?

I'm calling this function to load a TreeView with a list of the directories on the disk. private void LoadDirectories(string currentPath, TreeNodeCollection nodes) { DirectoryInfo directoryInfo = new DirectoryInfo(currentPath); DirectoryInfo[] directories = directoryInfo.GetDirectories(); foreach (DirectoryInfo dir in direc...

Recursion of internal functions in Erlang

Playing with Erlang, I've got a process-looping function like: process_loop(...A long list of parameters here...) -> receive ...Message processing logic involving the function parameters... end, process_loop(...Same long list of parameters...) end. It looks quite ugly, so I tried a refactoring like that: process_l...

Recursive (pedigree) tree building from (child, parent) list in Python

Hi All, I have as input a list of tuples (child, parent). Given that a child only have one parent. I would like for every child to build an ordered ancestors list. Any tip ? input would be like : [('3', '4'), ('1', '2'), ('2', '3')] output would be like: 1, [2, 3, 4] 2, [3, 4] 3, [4] 4, [None] ...

Simple recursion question.

Let's say we have a simple recursion like. int x(int a){ if(a<10) x(a+1); else !STOP! b++; return b; } Globaly: int b=0; In main we could have something like this: int p=x(1); Is there any way to stop the recursion so that the p will be 0, this means that "b++" will never be executed. I'll be grateful ...

How to store ordered items which often change position in DB

I need to be able to store a large list of ordered items in the DB. So far that's straight-forward: ID Position OtherFields 1 45 ... 2 4736 ... 3 514 ... ... In queries, I always need to get just a few items (filtered based on OtherFields) but in the correct order. Easy as well, putting an index on Position...

Is Hierarchical Recursive Grouping is possible in Tablix in RS2008?

Hi! Is Recoursive column grouping possible for tablix in RS2008? If yes, please provided related link ...

PHP recursive function, to create site navigation as nested list, but without unnecessary menu items.

I really dig the idea of using a recursice function to build my site menus but I am having a problem and have been banging my head for ages now. I need my menu function to return a nested list but I dont want non-active irelevent elements of the tree to be displayed. Details. I have a MySql database with a table called menu_items that s...

Walk folder tree, bottom up

I'm looking for ideas for fast and effective way to walk through folders bottom-up using C#/.NET 3.5 for example: -0 --1 ---12 --2 ---21 ---22 ---23 first walk though: 12,21,22,23 then: 1,2 Thanks ...

Mutually recursive classes

How do I implement mutually recursive classes in C++? Something like: /* * Recursion.h * */ #ifndef RECURSION_H_ #define RECURSION_H_ class Class1 { Class2* Class2_ptr; public: void Class1_method() { //... (*Class2_ptr).Class2_method(); //... } }; class Class2 { Class1* Class1_ptr; public: void C...

Python permutation generator puzzle

I am writing a permutation function that generate all permutations of a list in Python. My question is why this works: def permute(inputData, outputSoFar): for elem in inputData: if elem not in outputSoFar: outputSoFar.append(elem) if len(outputSoFar) == len(inputData): print outputSoF...

C# Create HTML unordered list from List using Recursion

Is it possible to output the following HTML unordered list using recursion. <ul> <li>1 <ul> <li>5 <ul> <li>8</li> <li>9</li> </ul> </li> <li>6</li> </ul> </li> <li>2</li> <li>3</li> <li>4</li> ...

How to stop basepage from recursivly detecting session timeout

Alternate Title: How to redirect on session timeout FINAL SOLUTION: Credit to: Robin Day (Although I tested Ben's solution and it also works and the other two solutions are also both good solutions) I got rid of the basepage that I had originally. Put this in the Session_Start of Global.asax void Session_Start(object sender, EventArg...

recursive string reverse function

writing a recursive string reverse function out of curiosity, but having a bit of problem with XOR there. The whole point of this function, is to not use iterator, which is why it is a recursive function. this is not homework, just curiosity. private static char[] ReverseNL(char[] arr, int index) { var len = arr.Length;...

Create random string, check if it exists, if it does create a new one.

I want to generate a random string of about 5 characters long. I can create it ok, but I'm having trouble checking if it exists in an array (or database in real situation) and creating a new one if it does. I use a function like this to generate the string: function rand_string(){ return substr(md5(microtime()), 0, 5); } But them...

T-SQL CTE Error: Types don't match between the anchor and the recursive part

I get the following error when I try to execute a particular recursive CTE: Msg 240, Level 16, State 1, Line 8 Types don't match between the anchor and the recursive part in column "data_list" of recursive query "CTE". This is nonsense. Each field is explicitly cast to VARCHAR(MAX). Please help me. I've read many answers to this prob...

mysql stored procedure that calles itself recursively

I have the following table: id | parent_id | quantity ------------------------- 1 | null | 5 2 | null | 3 3 | 2 | 10 4 | 2 | 15 5 | 3 | 2 6 | 5 | 4 7 | 1 | 9 Now I need a stored procedure in mysql that calles itself recursivly and returns the computed quantity. For example the i...

Maximum <jsp:include> depth.

We're using an application build using Weblogic Workshop 10.3 and running on weblogic server 10.3. I'm trying to display a tree of data using recursive calls to a jsp page using <jsp:include>. The problem I'm having is that after about 3-4 layers deep the page doesn't get rendered anymore. Log statements around the JSP include show th...

PostgreSQL SQL or PL/pgSQL query for traversing a directed graph and returning all edges found

Hi, I'm not particularly accustomed to generating complex SQL queries and am having difficulty in mixing my understanding of procedural languages and of set-based operations in devising a recursive query for network traversal. I wish to find the set of edges that lie 'upstream' of a particular node through conducting a depth first sear...

What is the simplest way to get a ratio in PHP of multiple numbers?

I've adapted this from an example that I found on the 'net... function ratio($a, $b) { $_a = $a; $_b = $b; while ($_b != 0) { $remainder = $_a % $_b; $_a = $_b; $_b = $remainder; } $gcd = abs($_a); return ($a / $gcd) . ':' . ($b / $gcd); } echo ratio(9, 3); // 3:1 Now I want it...

Stopping a recursive generator & permutations

As an exercise, I've been trying out various ways of generating all permutations of a list in Python -- recursive, non-recursive... -- and comparing the performance with itertools.permutations(). But I'm having trouble with the generator version of the recursive method, which doesn't finish cleanly with a StopIteration exception, but ins...