recursion

How can I write a function that returns a list of keys in a nested table?

I have a hierarchically nested associative array. It looks like this: A = { B = { C = {}, D = {}, }, E = { F = { G = {} } }, H = {} } I would like to write a function that returns the "ancestors" of each key. So: f("A") = {"A"} f("B") = {"B","A"} f("C") =...

Recursivly traverse simple tree in PHP

I have a simple tree which takes the shape below ROOT /\ A B / \ A1 B1 \ B11 This is stored in a DB table CLASSES that is self referencing. ID | CLASS_ID | PARENT_ID --------------------------- 1 | ROOT | 2 | A | ROOT 3 | A1 | A 4 | B | ROO...

How can I convert a text-file outline list into a recursive collection of objects?

How can I convert this text file content into a recursive collection of objects that I can bind to a TreeView? i.e. I want to end up with a collection of 3 objects, the first one called countries which has a collection of three child objects: france, germany, italy, and so on... ANSWER: thanks to all who helped out on this, here's my co...

Recursive list of lists in XSL

I have a recursive nodes that I'm trying to set up for jquery-checktree. The nodes look like foo/bar/ID /NAME /CHECKED bar/ID /NAME /CHECKED /bar/ID /NAME /bar/ID /NAME /bar/ID /NAME /CHECKED /bar/ID /NAME ...

jQuery too much recursion

Im trying to select a radio box when I click an LI. But i get the error "to much recursion". Code is: $('li').click( function(){ $('li.selected').removeClass('selected'); $(this).addClass('selected'); $(this).children("input[type=radio]").click(); }); This is using jQuery 1.4.2 and UI 1.7.2. ...

Sort array with recursive function call?

I need the following array in alphabetical order (at all levels), but asort doesn't seem to work because I have a recursive call in my function (or so I think); it only partially sorts my array, so I'll have chunks of it that are alphabetized, but they'll be out of order. Help! Ex. Directory Listing: apartments.html js/ application....

I'm trying to change my Maze traversal recursive coding part into a while loop.

Here's my code. #include <iostream> using namespace std; enum Direction { EAST, NORTH, WEST, SOUTH }; const int size = 12; int xStart = 2; int yStart = 0; char *maze2[ ] = { "############", "#...#......#", "..#.#.####.#", "###.#....#.#", "#....###.#..", "####.#.#.#.#", "#..#.#.#.#.#", "##.#.#.#.#.#", ...

setting scope of array_map php

hey all, i use array_map from time to time to write recursive methods. for example function stripSlashesRecursive( $value ){ $value = is_array($value) ? array_map( 'stripSlashesRecursive', $value) : stripslashes( $value ); return $value; } Question: say i wanna put this function in a static class, how would i use...

Recurrence Relations

I am currently enrolled in a programming class and we are covering recurrence relations. I was just wondering if, ever these actually get used on the job. If so, I'd love to hear some examples of when it is useful. ...

sbcl runs forever on second call of function

The function: Given a list lst return all permutations of the list's contents of exactly length k, which defaults to length of list if not provided. (defun permute (lst &optional (k (length lst))) (if (= k 1) (mapcar #'list lst) (loop for item in lst nconcing (mapcar (lambda (x) (cons item x)) (permute (remov...

PHP parse directory and subdirectories for file paths and names of only jpg image types

I am looking to modify this php code to do a recursive "search for and display image" on a single, known, directory with an unknown amount of sub-directories. Here's the code I have that scans a single directory and echoes the files out to html: <?php foreach(glob('./img/*.jpg') as $filename) { echo '<img src="'.$fil...

Recursive function in javascript

Maybe is a trivial problem, i don't know why this function exit from for cycle when it goes on else statement. I need this function to fetch an xml document. function xmlToArray(element){ childs= element.childNodes; if(childs.length != 1){ for(var i=0;i<childs.length;i++){ if(childs[i].hasChildNodes()){ x...

Search for content in functions with regex

Hello, How would I with regular expression search for functions which contains the use of a global variable without running "global $var" first? The files looks like this: class TestClass { function correctFunc() { global $var; $name = $var->name; } function invalidFuncIWantToFind() { $age ...

What languages do not have looping constructs?

Which languages are recursive-only languages? ...

Recursive subdirectory SQL problem

This is a mental excercise that has been bothering me for a while. What strategy would you use to solve this sort of problem? Let's consider the following simple database structure. We have directories, obviously a tree of them. Also we have content items, which always reside in some directories. create table directory ( directoryId ...

Implementing Recursive Comments in PHP/MySQL

I'm trying to write a commenting system, where people can comment on other comments, and these are displayed as recursive threads on the page. (Reddit's Commenting system is an example of what I'm trying to achieve), however I am confused on how to implement such a system that would not be very slow and computationally expensive. I imag...

PHP: Recursively get children of parent

I have a function which gets the ids of all children of a parent from my DB. So, if I looked up id 7, it might return an array with 5, 6 and 10. What I then want to do, is recursively find the children of those returned ids, and so on, to the final depth of the children. I have tried to write a function to do this, but I am getting co...

PHP tree implementation: Defining parent reference on recursion loop

Back to my JaxpTree object. The tree is supposed to convert a MySQL related-table pair into a nested tree that follows such relationship: /** * Generates a JaxpTree structure. Parameters are used by the recursive * function. Normally, they shouldn't be specified. * * @param int $parent_id * @param s...

Recursive routes in Rails

Is is possible to create a recursive route in Rails? I have an application, which allows a admin to create pages. The page model is a nested set and so each page has a parent_id hence the pages are structured in trees. The page model also uses the Friendly ID plugin to provide slugs for each page. When a user browses the site I would l...

Overloading << operator and recursion

Hi, I tried the following code: #include <iostream> using std::cout; using std::ostream; class X { public: friend ostream& operator<<(ostream &os, const X& obj) { cout << "hehe"; // comment this and infinite loop is gone return (os << obj); } }; int main() { X x; cout << x; return 0; }...