recursion

Why is my recursion keep throwing a StackOverflow error?

五迷三道 提交于 2020-01-17 05:21:25
问题 I am trying to generate a tree, of all the possible states of the 8-N problem, with no duplicates. I can do it on paper but in code I can't. Here is my recursive function: ...... ... .. root = new TreeNode(startingState); visitedStates.add(root.getData().getStateValues()); generateStateSpaceRecursive(root); } public void generateStateSpaceRecursive(TreeNode node){ List<TreeNode> nextStatesNodes = getNextStates(node); for (TreeNode childNode : nextStatesNodes){ if(!stateVisited(childNode

Haskell - parse error on input `=' [duplicate]

心不动则不痛 提交于 2020-01-17 04:32:28
问题 This question already has an answer here : Parse error in valid code [duplicate] (1 answer) Closed 5 years ago . when implementing the code for the "Towers of Hanoi" problem I get the following error message: hanoi.hs:4:24: parse error on input `=' Failed, modules loaded: none. Here is the code: hanoi 1 i j = [(i, j)] hanoi n i j = hanoi n' i otherT ++ [(i,j)] ++ hanoi n' otherT j where n' = n-1 otherT = 1+2+3-i-j Any Ideas? 回答1: Your editor and the compiler see the tabs differently. Avoid

A way to reverse a string using recursion in C strange to me

自作多情 提交于 2020-01-17 04:29:21
问题 I found the following code to reverse a string in C in my university notes. I do not understand how the recursion works in this example since it seems magic to me! To be more specific, if I type the word "one" the program prints out the word "eno" . According to the explanation, the function reads characters from the user recursively until the user presses Enter('\n') and then prints out the reversed word. But how is it possible to print the word if the last time the function calls itself

How to use a recursive function to update a table?

喜欢而已 提交于 2020-01-17 03:01:07
问题 This is a follow-up from this question. Functions are not allowed to write to the database, but what if I wanted to update a record every time a function was called, specifically a recursive function? Currently, I have a function that takes an ID and returns a float. I'd like to update a table using the given ID and the returned float. Ordinarily, a simple stored procedure could be used to call the function and then make the update. My function is recursive, and so the solution isn't that

Python function composition (max recursion depth error, scope?)

房东的猫 提交于 2020-01-17 01:10:36
问题 What is wrong with this function? It seems like a scope error (although I thought I had fixed that by placing each callable in the list, instead of using it directly). Error is max recursion depth reached (when calling comp(inv,dbl,inc))... Note: the question is: why is it even recursing, not why it's reaching the max depth... def comp(*funcs): if len(funcs) in (0,1): raise ValueError('need at least two functions to compose') # get most inner function composed = [] print("appending func 1")

Python function composition (max recursion depth error, scope?)

纵然是瞬间 提交于 2020-01-17 01:10:32
问题 What is wrong with this function? It seems like a scope error (although I thought I had fixed that by placing each callable in the list, instead of using it directly). Error is max recursion depth reached (when calling comp(inv,dbl,inc))... Note: the question is: why is it even recursing, not why it's reaching the max depth... def comp(*funcs): if len(funcs) in (0,1): raise ValueError('need at least two functions to compose') # get most inner function composed = [] print("appending func 1")

Recursive Perl detail need help

本秂侑毒 提交于 2020-01-16 18:27:20
问题 i think this is a simple problem, but i'm stuck with it for some time now! I need a fresh pair of eyes on this. The thing is i have this code in perl: #!c:/Perl/bin/perl use CGI qw/param/; use URI::Escape; print "Content-type: text/html\n\n"; my $directory = param ('directory'); $directory = uri_unescape ($directory); my @contents; readDir($directory); foreach (@contents) { print "$_\n"; } #------------------------------------------------------------------------ sub readDir(){ my $dir = shift

Typescript: recursive check nestest arrays

情到浓时终转凉″ 提交于 2020-01-16 14:04:12
问题 i have problem looping through a nested array that can contains arrays of itself... that should represent a dynamic menu as follow: this is how the objects are made: Interface IMenuNode: export interface IMenuNode { title: string; haveChildren: boolean; id: string; node: Array<IMenuNode>; link: string; img: string; value: string; } Class DataNode that implements IMenuNode export class DataNode implements IMenuNode { title: string; haveChildren: boolean; id: string; node: Array<IMenuNode>;

Typescript: recursive check nestest arrays

≡放荡痞女 提交于 2020-01-16 14:03:10
问题 i have problem looping through a nested array that can contains arrays of itself... that should represent a dynamic menu as follow: this is how the objects are made: Interface IMenuNode: export interface IMenuNode { title: string; haveChildren: boolean; id: string; node: Array<IMenuNode>; link: string; img: string; value: string; } Class DataNode that implements IMenuNode export class DataNode implements IMenuNode { title: string; haveChildren: boolean; id: string; node: Array<IMenuNode>;

Changes Cascading down to children in a Tree structure ASP.NET MVC 3

跟風遠走 提交于 2020-01-16 07:56:25
问题 This is for an ASP.NET MVC 3 application and deals with updating children nodes in a tree structure. The user is allowed to make changes to any part of a node in the tree. Once the user has made a change, (i.e. to a Status field) that change will have to be cascaded down to all the children. The issue is there are an arbitrary amount of children and their children have an arbitrary number on children and so on. How would I go about doing this? Thanks anyone who can help! EDIT I would like for