-1
голосов
5ответов
1712 просмотров

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 meth...

1
голосов
2ответов
1470 просмотров

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&...

6
голосов
3ответов
28770 просмотров

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

3
голосов
4ответов
2824 просмотров

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 Break or shortcircuit a fold in Scala) // Depth-first search of labyrinth, with large depth > stacklimit def search ( labyrinth: Sear...

14
голосов
9ответов
25546 просмотров

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 nonexist...

0
голосов
4ответов
4873 просмотров

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 th...

4
голосов
4ответов
6417 просмотров

Recursively creating a multi-dimensional array in PHP

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 me...

8
голосов
5ответов
7795 просмотров

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 ...

7
голосов
10ответов
2945 просмотров

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

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

0
голосов
7ответов
10301 просмотров

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 acce...

0
голосов
4ответов
2477 просмотров

Java recursive binary tree

Welcome! I have a recursive public static method named less that takes a tree node (an original binary tree, not really a search tree) and a int parameter that returns if all the values in the tree are less than the integer. So, I would use a public class TN { public int value; public TN left...

12
голосов
11ответов
10809 просмотров

Catching "Stack Overflow" exceptions in recursive C++ functions

Is it possible to catch a stack overflow exception in a recursive C++ function? If so, how? so what will happen in this case void doWork() { try() { doWork(); } catch( ... ) { doWork(); } } I am not looking for an answer to specific OS. Just in ge...

29
голосов
7ответов
37360 просмотров

How to delete empty subfolders with PowerShell?

I have a share that is a "junk drawer" for end-users. They are able to create folders and subfolders as they see fit. I need to implement a script to delete files created more than 31 days old. I have that started with Powershell. I need to follow up the file deletion script by deleting sub...

2
голосов
1ответов
1749 просмотров

Ocaml - Iterative to Recursion

For an assignment, i have written the following code in recursion. It takes a list of a vector data type, and a vector and calcuates to closeness of the two vectors. This method works fine, but i dont know how to do the recursive version. let romulus_iter (x:vector list ) (vec:vector) = ...

0
голосов
1ответов
475 просмотров

NHibernate many-to-one loading alternative

I have a Parent/Child object/mapping as follows: class Parent { int Id; string name; List<Child> children; } <bag name="Children" cascade="all" lazy="false "> <key column="ParentId" /> <one-to-many class="Child" /> </bag> class Child { int Id; Paren...

1
голосов
1ответов
424 просмотров

Java Need help implementing an algorithm

This algorithm is so advanced for my basic programming skills that I just don't see how I could implement it. I'm posting this in a new question because I can't keep bothering the guy who gave me the algorithm alone about this in the comment section in the previous question. MaxSet(node) = 1 if...

2
голосов
5ответов
140 просмотров

Are there any cases when I would want to use an explicit stack over recursion?

Are there any cases when I would want to use an explicit stack data-structure in my algorithms, as opposed to doing recursion (which uses the call stack)? Is there any benefit to doing it one way over the other? I would think using the explicit data-structure would be more performant because it...

0
голосов
2ответов
542 просмотров

Infinitely Deep Recursive Children

I have a single-table with the following (relative) structure: foo_id, parent_foo_id, foo_name I would like to build an (effectively) infinite-depth recursive array with these entities, and consequently output them into a tree menu. Nodes with no "parent_foo_id" would be considered at the to...

0
голосов
3ответов
747 просмотров

Copying a Directory Tree File by File

My advisor frequently compiles a bunch of software into his /usr/local and then distributes his /usr/local as a tarball. I then extract the tarball onto our lab machines for our use. Until now, this has worked fine, we just replace the old /usr/local with the contents of the tarball. But I have ...

1
голосов
1ответов
2497 просмотров

Recursive chmod in ruby on mac OS X?

I need to delete an application (MyApp.app), which has read only permissions in all its enclosed folders. Before I delete it, I should change the permissions on all enclosed files/directories to 0644. How do I do this recursively? I've tried begin; FileUtils.chmod(0644, '#{config.appPath}'); re...

0
голосов
1ответов
435 просмотров

Reducing values in one table until reserves depleted in another - recursion?

I have two tables - let's call them dbo.ValuesToReduce and dbo.Reserve The data in the first table (dbo.ValuesToReduce) is: ValuesToReduceId | PartnerId | Value ------------------------------------- 1 | 1 | 53.15 2 | 2 | 601.98 3 | 1 ...

0
голосов
2ответов
774 просмотров

constructing random "integer" tree - depth-first / breadth-first

This is my first ever attempt at writing a recursive function in c. The following-code works. I apologize for the long posting, but I am trying to be as clear as possible. I am trying to generate a tree where each node (inode) has an integer field "n". Correspondingly, each inode has an array ...

1
голосов
1ответов
145 просмотров

Lisp Recursion Not Calling Previous Functions

I'm trying to have a function compare the first argument of a passed in argument to a value, then if it is true, perform some function, then recursively call the same function. (defun function (expression) (cond ((equal (first expression) "+") (progn (print "addition") (fu...

8
голосов
1ответов
6394 просмотров

How does the Jinja2 "recursive" tag actually work?

I'm trying to write a very simple, tree-walking template in jinja2, using some custom objects with overloaded special methods (getattr, getitem, etc) It seems straightforward, and the equivalent python walk of the tree works fine, but there's something about the way that Jinja's recursion works ...

0
голосов
5ответов
1449 просмотров

Break string into separate lines: a showdown

Accommodating legacy database tables that were designed specifically for the IBM mainframe screens they represent has caused me much aggravation. Often, I find the need to break a string into multiple lines to fit the table column width as well as the users who are still viewing the data with ter...

0
голосов
1ответов
1287 просмотров

XSLT conditional node selection

Here is my problem. I have a "menu" organized like this: <menutree> <menuitem name="Foo"> <menuitem name="Sub-Foo"> <menuitem name="Sub-sub-foo1"/> <menuitem name="Sub-sub-foo2"/> <menuitem name="Sub-sub-foo3"/> </menuitem> ...

1
голосов
3ответов
3434 просмотров

Last occurence of element in a list in OCaml

Assuming l is a list and elem is an element, how can I return the last occurence of the element elem in the list l? Also return -1 if the element does not exisit in l. I don't quite understand how to use recursion for iterating through the list... let rec getLastOccurence l elem = …

2
голосов
2ответов
259 просмотров

authlogic crashes with infinite recursion

I have some trouble with using authlogic in my rails app, so I began using the blank example from github.com/binarylogic/authlogic_example which doesn't work either. I spent a day installing ruby 1.9.1 and 1.8 and jruby1.8, neither did work. The fun thing is that another rails app worked on my s...

0
голосов
1ответов
2320 просмотров

tail recursion sum, power, gcd in prolog?

how can I accomplish this: Give a tail-recursive definition for each of the following predicates. power(X,Y,Z): XY=Z. gcd(X,Y,Z): The greatest common divisor of X and Y is Z. sum(L,Sum): Sum is the sum of the elements in L. so far I have done this but not sure if that's correct power(_,0,1) ...

1
голосов
2ответов
1353 просмотров

XSLT - how to parse xml with recursive elements to Eclipse toc.xml?

I have the following XML: <HTML> <HEAD> <META name="GENERATOR" content="Microsoft HTML Help Workshop 4.1" /> <!-- Sitemap 1.0 --> </HEAD> <BODY> <OBJECT type="text/site properties"> <param name="FrameName" value="contents" /&gt...