recursion

Binary Search Trees

Hi there! I have a question with regards to the Binary Search Tree Implemetation in C++. Here is the question below Implement a simple (non-templated) BST which stores integers. Provide the following operations: Insert, Remove, inOrder traversal, preOrder traversal, postOrder traversal. Use recursive routines for dealing with the tree....

How do I read multiple directories and read the contents of subdirectories in Perl?

I have a folder and inside that I have many subfolders. In those subfolders I have many .html files to be read. I have written the following code to do that. It opens the parent folder and also the first subfolder and it prints only one .html file. It shows error: NO SUCH FILE OR DIRECTORY I dont want to change the entire code. Any mo...

Recursive image lazy-load failing in Internet Explorer (6-8)

Problem: I am having trouble implementing a recursive image lazy load in all relevant versions of Internet Explorer. I am using jQuery 1.3.2, and the code that follows works wonderfully on Firefox, Safari, and Chrome. While I would expect that IE6's javascript engine would choke, I am very surprised to find that it does not work at all...

Handling common recursive functions

I've noticed that in my project, we frequently are writing recursive functions. My question is: is there any way to create the recursive function as generic function for each hierarchy structure that is using the recursive iteration? Maybe I can use a delegate that gets the root and the end flag of the recursion? Any ideas? Thanks. ...

Recursively parsing XML in Actionscript 2

I'm looking for an efficient and reusable way to parse xml into an object in actionscript2. The xml structure itself might change so it's important that im able to parse the xml with out 'hard coding' specific nodes, etc. I normally use As3 and wouldn't need something like this since the XML class is easy to drill down into. Below is AS...

How can I increase the stack memory?

Duplicate of http://stackoverflow.com/questions/743545/how-to-allow-more-memory-and-avoid-stack-overflow-on-lots-of-recursion I'm writing a branch and bound algorithm which has at least 10000 levels by a recursive function,but it doesn't work due to a stack overflow error. here is a simple instance of my program in C++: void f(int k) {...

Recursive Incrementer

I'm writing a recursive function that takes a char array, which represents a number, and a pointer to a digit in that array. The point of the function is to increment the number just like the ++ operator. However, when I try it out on the number '819'. It doesn't increment it to '820' but instead changes it to '810' (it increments the...

Recursively generate ordered substrings from an ordered sequence of chars?

Edited after getting answers Some excellent answers here. I like Josh's because it is so clever and uses C++. However I decided to accept Dave's answer because of it's simplicity and recursion. I tested them both and they both produced identical correct results (although in a different order). So thanks again everyone. Say I have a st...

C++ Recursive File/Directory scanning using Cygwin

I'm looking to write a portable filesystem scanner, capable of listing all files on a given directory path recursively. To do this, I'm attempting to use cygwin for my compiler, making use of dirent.h and using the template: #include <dirent.h> #include <stdio.h> int main(void) { DIR *d; struct dirent *dir; d = opend...

How can I recursively visit links without revisiting links?

I want to check a site for links, and then recursively check those sites for links. But I don't want to fetch the same page twice. I'm having trouble with the logic. This is Perl code: my %urls_to_check = (); my %checked_urls = (); &fetch_and_parse($starting_url); use Data::Dumper; die Dumper(\%checked_urls, \%urls_to_check); sub ...

How to call recursive function in smarty?

$sql = "select menu_id , menu_name , parent_id from menu " ; $dbc->setFetchMode(DB_FETCHMODE_ASSOC); $res = $dbc->query($sql); while($row = $res->fetchRow()){ $menu[$row['parent_id']][$row['menu_id']] = $row['menu_name']; } function make_menu($parent) { global $menu ; echo '<ul>'; foreach($parent as $menu_id=>$menu_name)...

Recursive file copy and rename on the Vista command line

I'm trying to recurse through my music directory and copy every file called folder.jpg to a file in the same directory called cover.jpg. I've tried variations of suggestions in this question such as this: for /r %i in (folder.jpg) do copy %i cover.jpg Resulting in "The system cannot find the file specified." How can solve this probl...

Why are functions in Ocaml/F# not recursive by default?

Why is it that functions in F# and Ocaml (and possibly other languages) are not by default recursive? In other words, why did the language designers decide it was a good idea to explicitly make you type rec in a declaration like: let rec foo ... = ... and not give the function recursive capability by default? Why the need for an exp...

Recursive lambdas in F#

Take this example code (ignore it being horribly inefficient for the moment) let listToString (lst:list<'a>) = ;;' prettify fix let rec inner (lst:list<'a>) buffer = ;;' prettify fix match List.length lst with | 0 -> buffer | _ -> inner (List.tl lst) (buffer + ((List.hd lst).ToString())) inner lst "" ...

Could someone explain these Haskell functions to me?

I've dabbled with Haskell in the past, and recently got back into it seriously, and I'm reading real world haskell. Some of the examples they've shone, I've yet to understand. Such at this one: myLength [] = 0 myLength (x:xs) = 1 + myLength (xs) I don't see how this works, what is 1 really being added too? How is the recursion ret...

Recursive file search using C++ MFC?

What is the cleanest way to recursively search for files using C++ and MFC? EDIT: Do any of these solutions offer the ability to use multiple filters through one pass? I guess with CFileFind I could filter on *.* and then write custom code to further filter into different file types. Does anything offer built-in multiple filters (ie. ...

What are recursively enumerable sets?

There seems to be a lot of discussion (and confusion) regarding the Wikipedia article on the topic. Other results Google throws up are not available for free public use. I would be interested in what you folks have to say. Thanks! ...

Method to count all items in Hierachical object list

I've got a simple class defined as: public class MyClass { //Some properties public List<MyClass> SubEntries { get; set; } //Some more properties } In another class I have a list of the above type. At the moment, I'm having a serious mental block. I just need to itereate through the list and count all occurances of MyClass....

How do recursive ascent parsers work?

How do recursive ascent parsers work? I have written a recursive descent parser myself but I don't understand LR parsers all that well. What I found on Wikipedia has only added to my confusion. Another question is why recursive ascent parsers aren't used more than their table-based counterparts. It seems that recursive ascent parsers ha...

given a tree structure, how do you use recursion to make it into a simple linked list in-place?

Given a binary tree (with left and right child only), how do you write a recursive function to make it into a simple linked list in-place? (no new data structure should be created. Pseudo code is ok). Suppose each node has an integer value, like 123, or 2, or 3. The final link list should have all the nodes in the tree. The order is n...