recursion

Recursion using C language

When I compile this program I only get the first capital letter but not the rest. Input: ABldjfdslkjfCK I only get 'A' that is it? #include <stdio.h> #include <string.h> FILE *fp; int main(void) { int size; char input[100]; // array size of 100 if (fp = fopen("message.txt","r")) // file exists { fge...

How can I traverse a file system with a generator?

I'm trying to create a utility class for traversing all the files in a directory, including those within subdirectories and sub-subdirectories. I tried to use a generator because generators are cool; however, I hit a snag. def grab_files(directory): for name in os.listdir(directory): full_path = os.path.join(directory, name...

Howto create combinations of several vectors without hardcoding loops in C++?

I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A Vector3_elements = C,G,T ..... up to ... VectorK_elements = ... #Note also that the member of each vector is always 3. What I want to do is to create all combination of elements in Vector1 through out VectorK. Hence in the end we hope to get t...

PHP recursive function + array by reference = headache

I have an interesting problem. The basis of the problem is that my last iteration of an array reference doesn't seem to "stick," if you will. A little context: I've devised a very simple data structure for page heirarchy that looks like this: ,1,2,3>,4>,5,6,7<<,8 Translation: forget about the annoying leading commas. Pages 1, 2, 3, & 8...

How to capture a string into variable in a recursive function?

I tried to print all the possible combination of members of several vectors. Why the function below doesn't return the string as I expected? #include <iostream> #include <vector> #include <fstream> #include <sstream> using namespace std; string EnumAll(const vector<vector<string> > &allVecs, size_t vecIndex, string strSoFar) {...

Remove .listing files recursively from Windows filesystem

Is there any command to recursively remove .listing files from a Windows folder? ...

PHP Recursively unset array keys if match

I have the following array that I need to recursively loop through and remove any child arrays that have the key 'fields'. I have tried array filter but I am having trouble getting any of it to work. $myarray = array( 'Item' => array( 'fields' => array('id', 'name'), 'Part' => array( 'fields' => array('pa...

Make a recursive function in SQL Server 2005

cat_id prod_name parent_cat_id ------ ---------- ------------ 1 prod_1 2 2 prod_2 5 3 prod_3 1 4 prod_4 3 5 prod_5 7 6 prod_6 5 In a recursive function, make a table and by using these, if cat_id = 1 and parent_cat_id = 1 take that product name and if that product category id and parent category id is sam...

How does primitive recursion differ from "normal" recursion ?

I am currently reading Simon Thompson's The Craft of Functional Programming and when describing recursion, he also mentions a form of recursion called Primitive Recursion. Can you please explain how this type of recursion is different from "normal" recursive functions? Here's an example of a primitive recursion function (in Haskell): ...

[PHP] Can this recursive function go crazy?

function generate_session_id( &$db ) { $user_sess_id = md5( uniqid( mt_rand(), true ); try { $stmt = $db->prepare("SELECT COUNT(*) AS session_exists FROM sessions WHERE session_id = :session_id"); $stmt->bindParam(':session_id', $user_sess_id); $stmt->execute(); $result = $stmt->fetch( PDO::FE...

Datatable in ASPX Used As DataSource For Multiple User Controls

In an ASPX page, I have 7 user controls loaded. In each user control there are data bound controls (gridview for example). Currently each user control runs a query to return data. The data returned is the same for each user control, and I filter out what I need to show for each user control. So the same query is being run 7 times (Ye...

Does pthreads support a method for querying the "lock count" of a recursive mutex?

Does pthreads support any method that allows you to query the number of times a recursive mutex has been locked? ...

Printing A String Vertically Using Recursion In Java

Hey I'm working on a problem where you would print a string vertically using recursion. I know how to do this if i were to use a for loop: for (int i = 0; i < str.length(); i++) { System.out.println(str.charAt(i)); but i'm not entirely sure how to do it using recursion. I took care of the base case but i'm not sure how to continue...

Wpf Recursive Binding

I'm trying to figure out how to build a recursive binding in xaml. I know about HierarchialDataTemplate, but that's not what I want, because my data source is not a collection of items. Specifically, I'm building an exception browser, and am trying to figure out the best way of expressing the exception's InnerException field (which is of...

Calculating the depth of a binary tree in LISP recursively

I have the following binary tree A / \ B C / \ D E represented as a list in Lisp (A 2 B 0 C 2 D 0 E 0) where the letters are node names and the numbers are the number of child nodes (0 for none, 1 one node, 2 two nodes). I need to find highest from root node to leaf depth of the tree (the depth of the binary tree that is)...

Using Recursion To Compare Strings To Determine Which Comes First Alphabetically Java

I am trying to write a method that uses recursion to compare the strings str1 and str2 and determine which of them comes first alphabetically (i.e., according to the ordering used for words in a dictionary). If str1 comes first alphabetically, the method should return the integer 1. If str2 comes first alphabetically, the method shoul...

Print Alternating Characters From Two Strings (Interleaving) Using Recursion Java

I'm trying to write a method that uses recursion to print the string formed by "interleaving" the strings str1 and str2. In other words, it should alternate characters from the two strings: the first character from str1, followed by the first character from str2, followed by the second character from str1, followed by the second charact...

Calculating a product recursively only using addition

I don't know why the following haskell source code for calculating products recursively only using addition doesn't work. mult a b = a + mult a (b-1) I'm always getting a stack overflow error. ...

Bash - Recursively Create Nonexistant Subdirectories

Hello all, I am creating a quick backup script that will dump some databases into a nice/neat directory structure and I realized that I need to test to make sure that the directories exist before I create them. The code I have works, but it seems that there is a better way to do it. Any suggestions? [ -d "$BACKUP_DIR" ] || mkdir "$BACK...

Any way to recursively update a tree in SQL?

I've got a database table that represents a bunch of trees. The first three columns are GUIDs that look like this: NODE_ID (PK) PARENT_NODE_ID (FK to same table, references NODE_ID) TREE_ID (FK to another table) It's possible to move a node to a different tree. The tricky part is bringing all its child-nodes with it. That takes a r...