recursion

Java Binary Search Tree Recursive Copy Tree

妖精的绣舞 提交于 2020-01-05 07:42:47
问题 I'm working on a problem which requires me to copy a binary search tree recursively and to return the tree. I am coding in the binary search tree class, so it will copy whatever binary search tree it is called on. The requirements say that the private method must have a return type of Entry<E> and a parameter of type Entry<E> . The problem I'm running into is getting multiple entries added to the tree. Here is what I currently have: public BinarySearchTree<E> rcopy(){ BinarySearchTree newTree

Check if all the letters in a string are capital recursively

空扰寡人 提交于 2020-01-05 07:16:27
问题 I have to check if all the letters are capital letters in recursion, and i dont know why this isnt working: public static bool IsCapital(string str) { if (str.Length == 1) return int.Parse(str[0].ToString()) > 65 && int.Parse(str[0].ToString()) < 90; return IsCapital(str.Substring(1)) && int.Parse(str[0].ToString()) > 65 && int.Parse(str[0].ToString()) < 90; } It crashes and says: "Unhandled exception: System.FormatException: Input string was not in a correct format." Console.WriteLine

How to build a recursive structure with MongoDB

两盒软妹~` 提交于 2020-01-05 07:15:10
问题 I'm trying to do something usually simple with SQL (with foreign key in the same table for example) (it may be as easy with MongoDB, I just don't know yet) which is to build a recursive data structure. For this example, I'll talk about Pages in a Website. I'd like to make a multiple level page structure. So there could be: Home Our Products Product 1 Product 2 About us Where are we? Contact us Let's say pages would have a title and a content. I need to know what's the best way to do this, and

How to build a recursive structure with MongoDB

我只是一个虾纸丫 提交于 2020-01-05 07:15:01
问题 I'm trying to do something usually simple with SQL (with foreign key in the same table for example) (it may be as easy with MongoDB, I just don't know yet) which is to build a recursive data structure. For this example, I'll talk about Pages in a Website. I'd like to make a multiple level page structure. So there could be: Home Our Products Product 1 Product 2 About us Where are we? Contact us Let's say pages would have a title and a content. I need to know what's the best way to do this, and

Recursive rendering of components at all levels

戏子无情 提交于 2020-01-05 06:25:34
问题 I need help in to recursively render the components at all levels. There are Nodes at top level and then the same structure is followed till the end. If we get Privilege we render it differently however all Categories need to be displayed above. Please find a fiddle here: https://jsfiddle.net/vedvrat13/dq0u2pm7/ Expected Output: --Category 1 ----SubCategory 1 ------Privilege 11 --Category 2 ----SubCategory 2 ------Privilege 21 ------Privilege 22 Please help me with the same. I tried multiple

Scheme accumulative recursion with lists

╄→гoц情女王★ 提交于 2020-01-05 06:01:19
问题 How can I pass a list as a parameter to a function adding elements to it recursively,and have it unmodified when it comes out of recursion? I want to use the list at each level of recursion with the list having the values added by deeper recursion levels. To be more specific I want to do a DFS search on a graph and I want to store in the list the nodes I visited. 回答1: One method of doing this is just to return the list so you have access to it at higher levels of recursion. Another method is

Scheme accumulative recursion with lists

陌路散爱 提交于 2020-01-05 05:57:05
问题 How can I pass a list as a parameter to a function adding elements to it recursively,and have it unmodified when it comes out of recursion? I want to use the list at each level of recursion with the list having the values added by deeper recursion levels. To be more specific I want to do a DFS search on a graph and I want to store in the list the nodes I visited. 回答1: One method of doing this is just to return the list so you have access to it at higher levels of recursion. Another method is

Recursive function using lambda expression

北城余情 提交于 2020-01-05 05:44:17
问题 I need to create a recursive function repeat which takes in a function and uses the function n number of times with the value of x. Here's an iterative version that explains my issue a bit more in detail. def repeat(fn, n, x): res = x for i in range(n): res = fn(res) print(res) return res print(repeat(lambda x: x**2, 3, 3)) returns 6561 First it takes 3^2, then 3^2^2 which is 81 then again 3^2^2^2 = 6561. How can i make this recursive so it can work like this. square_three_times = repeat

Recursive Scheme Function Value Error

女生的网名这么多〃 提交于 2020-01-05 05:00:12
问题 I am writing a small hangman game in scheme and am getting a very weird issue that almost seems like a language specific one. In my game I have a variable that holds the number of mistakes allowed and on each recursive call of my game loop, I "let" the value to a new one if it needs to be changed. Here is some code to help visualize how I run the game loop. guessed_list - a list of string characters containing old guesses and one new guess (ex. '("a" "x" "b") where "a" is the new guess) game

Iterative tree serialization function

99封情书 提交于 2020-01-05 04:35:12
问题 Here is a visual representation of the tree I'm working with and the desired string serialization: Here is a recursive solution: function* serialize(root) { if (root.length === 0) return; const [x, xs] = root; yield x; for (let i = 0; i < xs.length; i++) yield* serialize(xs[i]); yield ")"; } const Node = (x, ...xs) => ([x, xs]); const tree = Node("a", Node("b", Node("e"), Node("f", Node("k"))), Node("c"), Node("d", Node("g"), Node("h"), Node("i"), Node("j"))); console.log( Array.from