recursion

how to create a collection from list of strings that represents a directory structure in C# or VB

ε祈祈猫儿з 提交于 2019-12-24 15:13:45
问题 First, I did check this post but it is in Python, first, and second it appears to be actually making the directories, which I cannot do in this scenario. Second, these are not directories that exist, nor can I create them. I have an input in C# like this: List<string> filePaths = new List<string>(); filePaths.Add(@"ProgramDir\InstallDir\Module1\mod1pack1.exe"); filePaths.Add(@"ProgramDir\InstallDir\Module1\mod1pack2.exe"); filePaths.Add(@"ProgramDir\InstallDir\Module2\mod2pack1.exe");

Python recursively appending list function

自闭症网瘾萝莉.ら 提交于 2019-12-24 14:43:09
问题 Having issues with a recursive function that should be relatively simple to do, but can`t seem to get right. I have a folder structure with folders that can contain other folders, images or files. Associated with each folder there are permissions. I want to have my function recursively build a list of the permissions that are associated with each folder. I have a function has_read_permission(request) that returns True if the folder has permissions and False if not I have built a function like

Recursive Insert for Binary Tree

半世苍凉 提交于 2019-12-24 14:25:55
问题 I'm working on code for insertion into a binary search tree. It works for the first node I insert, making it the root, but after that it doesn't seem to insert any nodes. I'm sure it's a problem with setting left/right references, but I can't quite figure it out. Please help! //params: key of node to be inserted, parent node public void insert(int newKey, TreeNode parent){ //if the root of the tree is empty, insert at root if(this.getRoot() == null){ this.root = new TreeNode(newKey, null,

Python recursive function executing return statement incorrectly?

谁说我不能喝 提交于 2019-12-24 13:51:47
问题 I am working on a simple game which involves 2 players. Each player has two counters which they can move individually by selecting them. Player 1 has counters 1 and 1, whilst player 2 has counters 3 and 4. In order to prevent a player from moving one of their opponents counters I have written the following recursive function. It works fine if no one 'cheats'. If a player cheats, the function gets them to re-enter a correct counter number. This is carried through to the final return statement

converting a recursion to iteration in python

不打扰是莪最后的温柔 提交于 2019-12-24 13:51:33
问题 I wrote the below python script that sorts the elements of an array using divide-and-conquer (recursive calls). One of my friend suggested that recursion is slower than iteration. Is there a way to convert the below program to a 'for' loop and still leverage divide-and-conquer strategy. Will iteration beat recursion even if the list contains a lot of elements? ### Using recursion import random from datetime import datetime start = str(datetime.now().time()).split(':') def quicksort(A,first

Seg fault with iterators in a recursive function

烂漫一生 提交于 2019-12-24 13:19:08
问题 I'm trying to sort integers in a vector using a recursive function. My program runs, compiles, and sorts the data, but after the fact it gives me a seg fault. I think its because of the for loop using the addresses in the vector that have been changed causing it to never leave the loop. void Plays::SortRelevance(vector<Plays> list){ cout << "in the loop" << endl; for(vector<Plays>::iterator i=list.begin(); i != list.end(); ++i){ cout << i->relevance << endl; } for(vector<Plays>::iterator i

Can recursion be dynamic programming?

我是研究僧i 提交于 2019-12-24 13:16:33
问题 I was asked to use dynamic programming to solve a problem. I have mixed notes on what constitutes dynamic programming. I believe it requires a "bottom-up" approach, where smallest problems are solved first. One thing I have contradicting information on, is whether something can be dynamic programming if the same subproblems are solved more than once, as is often the case in recursion. For instance. For Fibonacci, I can have a recursive algorithm: RecursiveFibonacci(n) if (n=1 or n=2) return 1

Binary Search using Recursion

一曲冷凌霜 提交于 2019-12-24 12:51:48
问题 public static int binarySearch(double[] arr, int low, int high, double inq){ int mid = (low + high)/2; if(arr == null) return -1; if(low > high) return -1; if(arr[(int)inq] < arr[low]) return -1; if(arr[(int)inq] > arr[high]) return -1; } I am suppose to search through the array arr recursively to find the index of inq . All I have is the termination cases. Not sure how to go about this problem. The original question is this one: search the array slice arr[low:high] for an occurrence of inq.

Creating executable for Python 2.7, getting RuntimeError: maximum recursion depth

对着背影说爱祢 提交于 2019-12-24 12:47:03
问题 I am running Python 2.7. I downloaded py2exe version 0.6.9 win32 to create an executable out of my .py file. I know it is an older version so I'm not sure if that's what's creating the error. I have gone through the steps: creating a setup.py file: from distutils.core import setup import py2exe setup(console=["MyFileName.py"]) Then running python setup.py py2exe --help from the command window, then python setup.py py2exe However, it turns up a RuntimeError: maximum recursion depth exceeded

Help with PHP recursive navigation list menu

匆匆过客 提交于 2019-12-24 12:44:13
问题 I am trying to add a dynamic recursive navigation list menu to a site of am working on. The scenerio is that the menu has 2 levels related by a parentid(preid). My issue is that I can display the 1st level list correctly, however I cannot get the second level to display properly. I am not sure where to add the UL and /UL tags for the second level. This is what I am after <ul> <li>Item 1</li> <li>item 2</li> <li>item 3</li> <ul> <li>sub item 1</li> <li>sub item 2</li> </ul> <li>Item 4</li> <li