recursion

Recursively search through sub directories for specified directory name in node

亡梦爱人 提交于 2020-06-17 09:19:26
问题 I have a directory structure like this: /git /content /repo1 /repo2 /repo3 /modules /repo4 /repo5 /tools /project /repo6 /repo7 /test /repo8 /repo9 I'd like to be able to find the path to a particular repo just by passing the repo name: searchDirForSubdir('/git', 'repo7'); // expected to return /git/tools/project/repo7 The function I have at the moment (below) returns undefined , even though the console.log call spits out the correct path. I know I'm messing up the recursion, but can't work

deleting a node from a binary search tree using recursion

点点圈 提交于 2020-06-17 09:10:02
问题 So I'm trying to delete a node from a tree by using these two functions inside the class.Unfortunately it just doesnt delete anything and i was wondering what is wrong about it! any help would be truly appreciated. def Find_Min(self,node): current=node while current.left is None: current=current.left return current def deletenode(self,node,ntbd): ##ntbd:node to be deleted /// node: root node if node is None: return None elif node.data>ntbd: node.left=self.deletenode(node.left,ntbd) elif node

deleting a node from a binary search tree using recursion

筅森魡賤 提交于 2020-06-17 09:09:33
问题 So I'm trying to delete a node from a tree by using these two functions inside the class.Unfortunately it just doesnt delete anything and i was wondering what is wrong about it! any help would be truly appreciated. def Find_Min(self,node): current=node while current.left is None: current=current.left return current def deletenode(self,node,ntbd): ##ntbd:node to be deleted /// node: root node if node is None: return None elif node.data>ntbd: node.left=self.deletenode(node.left,ntbd) elif node

How to convert an iterative function that checks for cycles in an adjacency matrix, to a simpler, recursive function in C?

半城伤御伤魂 提交于 2020-06-16 18:41:48
问题 Having trouble grasping recursive thinking, and a lot of what I've seen on Stack overflow so far I don't understand. I'm trying to detect a cycle in a directed graph, given a 2D array adjacency matrix where a value of true for graph[i][j] indicates an edge from i to j. Have created a check_cycles function which checks for a path from j to i, given graph[i][j] and have hard coded the size of the graph to simplify the issue. I am getting a return value of true as expected with this code, but as

How to convert an iterative function that checks for cycles in an adjacency matrix, to a simpler, recursive function in C?

孤者浪人 提交于 2020-06-16 18:40:31
问题 Having trouble grasping recursive thinking, and a lot of what I've seen on Stack overflow so far I don't understand. I'm trying to detect a cycle in a directed graph, given a 2D array adjacency matrix where a value of true for graph[i][j] indicates an edge from i to j. Have created a check_cycles function which checks for a path from j to i, given graph[i][j] and have hard coded the size of the graph to simplify the issue. I am getting a return value of true as expected with this code, but as

How replace item in tree recursively

老子叫甜甜 提交于 2020-06-16 17:29:25
问题 I'm trying to create a tree. But I dont know how replace a item recursively inside a tree. I have an array of items, each item if is on top parentId is undefined and if has clindren, each children has a parentId property that show how is his parent. I'm trying to create a method that find that item inside children property, who can have 1 or more levels. And if its possible return updated array This is my code: const onChangeStatusEditable = () => { const updatedBranch: IBranch = Object

Nested Predicates In Prolog

送分小仙女□ 提交于 2020-06-16 17:24:34
问题 I am trying to write a predicate that ‘exists’ inside the ‘scope’ of another predicate . The reason I need this is because both predicates make use of the same very large parameters/arrays and the predicate I want to nest is doing self recurssion many times , so I want to avoid copying the same parameters . So , is there any way i can do this in Swi-Prolg ? Thanks in advance . 回答1: You don't need to. You have to realize that all the terms "named" by Prolog variable names are already global ,

Recursive depth function on an array

让人想犯罪 __ 提交于 2020-06-16 03:04:33
问题 I have an array of objects like this input, and I want to nest some objects inside another objects (based if their parentId is the parents' forumId), I got the function working but up to 1 depth, how can I get it working for n depth? Any idea or optimizations are appreciated! EDIT: After pointing out, the input isn't necessarily ordered. const input = [ { forumId: 1, parentId: null, forumName: "Main", forumDescription: "", forumLocked: false, forumDisplay: true, }, { forumId: 2, parentId: 1,

Recursively iterate through a nested dict and return value of the first matching key

青春壹個敷衍的年華 提交于 2020-06-16 02:55:14
问题 I have a deeply nested dict and need to iterate through it and return the value corresponding to the key argument, second argument of my function. For example, with tree = {"a": 12, "g":{ "b": 2, "c": 4}, "d":5} tree_traverse(tree, "d") should return 5 Here is my code: def tree_traverse(tree, key): for k,v in tree.items(): if isinstance(v, dict): tree_traverse(v, key) elif k == key: return v The problem I have is that this function returns None if it doesnt find the matching key once it's

Remove key and its value in nested dictionary using python

£可爱£侵袭症+ 提交于 2020-06-13 09:22:40
问题 Looking for a generic solution where I can remove the specific key and its value from dict. For example, if dict contains the following nested key-value pair: data={ "set": { "type": "object", #<-- should remove this key:value pair "properties": { "action": { "type": "string", #<-- should NOT remove this key:value pair "description": "My settings" }, "settings": { "type": "object", #<-- should remove this key:value pair "description": "for settings", "properties": { "temperature": { "type":