recursion

Palindrome Recursion Program

public static boolean palindrome(String input, int i, int j) { if (i >= j) return true; if (input.charAt(i) == input.charAt(j)) { i++; j--; palindrome(input, i, j); } else if (input.charAt(i) != input.charAt(j)) return false; } My Java platform (eclipse) won't accept this code as working, due to a "lack of re...

Tree View in c# with recursive

hi there i have table in DB with 3 column => ParentId , Id , Text i wanna make Tree in C# by the Records that we have saved in this table i dont know how should i write my recursive method in c# please help me thanks ...

Without using recursion how can a stack overflow exception be thrown?

Without using recursion how can a stack overflow exception be thrown? ...

C#: Exception handling in recursive call

I have a recursive method call. When any exception is thrown, I would like to see, where in the recursive call stack it happened. I have a field which holds a "path" which represents the recursion stack. Now I would like to add the path information to any exception that could possibly be thrown in the recursive call. void Recursive(int...

Recursively creating a multi-dimensional array in PHP

Hi guys, I am trying to figure out the best way to write a PHP function that will recursively build a multi-dimensional array with an unknown number of sublevels from a mysql table. Its purpose is to create a data structure which can be looped through to create a navigation menu on a website, with each menu item possibly having a submen...

recursively find subsets

Here is a recursive function that I'm trying to create that finds all the subsets passed in an STL set. the two params are an STL set to search for subjects, and a number i >= 0 which specifies how big the subsets should be. If the integer is bigger then the set, return empty subset I don't think I'm doing this correctly. Sometimes it's...

How to implement recursive put in sftp

Command-line sftp in my Ubuntu doesn't have recursive put implemented. I found some debate from 2004 about implementing such feature with -R option switch. So I see some sort of self-made recursion as only option. Ie. iterate through directory listing cd into directories mkdir them if nonexistent put files I'm planning on doing this...

Limiting recursion depth in Scala

Can you always structure a recursive function for tail-call elimination? If not, what are other strategies to limit the stack size? For example: (inspired by http://stackoverflow.com/questions/1595427/break-or-shortcircuit-a-fold-in-scala) // Depth-first search of labyrinth, with large depth > stacklimit def search ( labyrinth: Search...

Traverse a XML using Recursive function

How can I traverse (read all the nodes in order) a XML document using recursive functions in c#? What I want is to read all the nodes in xml (which has attributes) and print them in the same structure as xml (but without Node Localname) Thanks ...

linear towers of hanoi

I have a question on the linear Towers of Hanoi. I implemented it in C++ but am trying to do the same using the tail recursive or iterative method. I am having trouble with my algorithm. This code snippet shows transferring blocks from the middle tower to the end tower. #include <stdlib.h> #include <stdio.h> using namespace std; //i...

Starting with Java recursion (probably an easy ? for most)

Hi I am working on the following problem: Write a recursive function that calculates the sum of the negative numbers of the array. Pass in the array {15 , -7 , -19 , 8 , 5 , -6 , -1} from the main method . The recursive function should return the result -33 . Print out this value in the main method. This program should be named Negsum....

Recursion - Python, return value question

Hello, I realize that this may sound like a silly question, but the last time I programmed it was in assembler so my thinking may be off: A recursive function as so: def fac(n): if n == 0: return 1 else: return n * fac(n - 1) Why is it that when the function reaches n == 0 that it does not return 1 but rather...

C#: How to make this method non-recursive

I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) { foreach (var d in directory.GetDirectories()) { DeleteEmpty(d); } if (directory.GetFileSystemInfos().Length == 0) { try { direc...

How to call a function inside itself?

I have a function that generates a key of 4 characters that has to be unique for each time. In order to do that, the function first generates a key, and then checks a database table to see if it's in use by someone else. If it's not in use, it returns the key, else, it calls itself again, but this causes the function to do an infinite l...

PHP - FTP subdirectory recursively?

The code below works insomuch that I can successfully download the directory recursively. But, I want to download the directories within this directory. So, when it connects it's in . Within the . directory is a subdirectory "In". I want to recursively retrieve the contents within the In directory. The directory names themselves wil...

A javascript recursion problem

I'm writing a js recursion function to find all ancestors of an element a user clicked on. my code is like this: /**a global variable.*/ var anc; function getAncestors(e){ var ele = e.target; var parentName = ele.parentNode.name; anc +=bracket(parentName); if (parentName.toLowerCase() == "undefined" ) return; else ge...

Sql Get all children of a parent

Lets say I have an Areas Table ( id, parentId, name, path ). Given an Id, I'd like to get all childrens (children of children included, recursively) of the given area. I do store in the path the path from the parents to the child. Example: 1 NULL New York /1/ 2 1 BRONX /1/2/ 3 1 MANH /1/3/ 4 3 UpWest /1/3/4/ 5 3 ...

Learning Java Recursion, Ackerman function

I'm working on a recursive Ackermann function in Java. I am getting an error at may recursive line, 23. return Ack(m - 1, Ack(m, n - 1)); Thanks so much if anyone could point out what's wrong. -Kyle /*enter code here Ackerman's function, A(m, n) is defined: A(0 , n) = n + 1 for n >= 0 A(m , 0) = A(m – 1 , 1) ...

PocketPC c++ windows message processing recursion problem

Hello, I am having a problem in a large scale application that seems related to windows messaging on the Pocket PC. What I have is a PocketPC application written in c++. It has only one standard message loop. while (GetMessage (&msg, NULL, 0, 0)) { { TranslateMessage (&msg); DispatchMessage (&msg); } } We also have ...

C++ template recursion - how to solve ?

Im stuck again with templates. say, i want to implement a guicell - system. each guicell can contain a number of child-guicells. so far, so tree-structure. in std-c++ i would go for sthg. like: template <typename T> class tree { public: void add (T *o) { _m_children.push_back (o); } void remove (T *o) { ... }; list<T*>...