recursion

C++ vector loses data in recursive function

主宰稳场 提交于 2020-01-04 09:12:45
问题 I am very new to C++ and I am trying to implement a TriangleDynamic object that can recursively split itself using a function called splitTriangleProject. It splits itself into four smaller TriangleDynamic objects (and projects the vertices of the new triangles onto a sphere with a given radius and origin, but I believe this is beside the point), pushes the newly created triangles into a vector that is part of the member data of the original object. The vector member data is called

Designate a variable as a list without overwriting it in a function

梦想与她 提交于 2020-01-04 05:54:18
问题 I created a function that will flatten a nested list into an ordinary list. outputarray = [] def flattenarray(x): for elmt in x: if isinstance(elmt, float) or isinstance(elmt, int): outputarray.append(elmt) elif isinstance(elmt, list): flattenarray(elmt) return outputarray The above works perfectly, but I am trying to have the "outputarray" variable inside the function, but when I do, the recursion step will overwrite the outputarray list back into an empty list. How can I make this work to

how to convert filenames with special characters to valid filenames?

北城余情 提交于 2020-01-04 05:48:22
问题 I would like to know whether it is possible to REMOVE special characters recursively in powershell from all files in an entire directory structure? for example if I have a file called: my presentation (fix).xlsx I would like to rename it to: my presentation fix.xlsx thank you for your guidance. the reason we need to do this is we are migrating many files into sharepoint 2010 and sharepoint doesnt like files with special characters! 回答1: I haven't tested this code, but I think you probably

How to optimize a recursive algorithm to not repeat itself?

雨燕双飞 提交于 2020-01-04 05:45:09
问题 After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my needs, a generic "diff"-ing module was written to solve a problem space. After having several months to think more about what it is doing, the recursive algorithm appears to be searching more than in needs to by re-searching the same areas in a sequence that a separate "search thread" may have also examined. The purpose of the diff module is to compute the difference and similarities between a

How does this compute ? I am trying to understand how the values of H get assigned in the list

你离开我真会死。 提交于 2020-01-04 05:20:49
问题 This predicate should print a list of size N containing possible permutations of 0 and 1 . My question is : does the value of H get carried over with each recursion or does the creation of the list with values of bit(H) take place in the backtracking phase? bit(0). bit(1). gen(0,[]). gen(N,[H|T]) :- N > 0, bit(H), N1 is N - 1, gen(N1,T). 回答1: Prolog execution is all about choice points. Here a choice point is left at each recursion step by the bit/1 predicate. When you ask Prolog to give you

finding depth of a tree?

拈花ヽ惹草 提交于 2020-01-04 04:55:45
问题 I am very new to binary tree and recursion. My program is to find the height of the tree but I am a bit confused as to why my program doesn't work. struct Node { int value; Node *left; Node *right; } int heightOfTree(Node node){ if(node ==NULL) { return 0; } else { int lheight=heightOfTree(node->left); int rheight = heightOfTree(node->right); if(lheight>rheight) { return lheight; } else { return rheight; } } } I followed a pseudocode online so I implemented it myself because I don't want to

Decimal to Binary in Lisp - make a non-nested list

拥有回忆 提交于 2020-01-04 02:54:12
问题 When reaching my recursion cases, I use list to append the future result with the current one, but I end up with a nested list because of recursion. This causes an error when I have a number that causes recursion for more than five times. Any ideas how I can get results in a single plain non-nested list, e.g.: CL-USER 100 : 8 > (BINARY_LIST 4) (1 0 0) Code & Example output: CL-USER 99 : 8 > (defun binary_list (i) (COND ((= i 0) 0) ((= i 1) 1) ((= (mod i 2) 0) (list (binary_list (truncate i 2)

How to read all records recursively and show by level depth TSQL

爷,独闯天下 提交于 2020-01-04 02:46:07
问题 Is there a way to read records recursively in similar table and order by depth level? #table: id int | parent int | value string -------------------------------------------- 1 -1 some 2 1 some2 3 2 some3 4 2 some4 5 3 some5 6 4 some6 7 3 some5 8 3 some5 9 8 some5 10 8 some5 So is there a way to recursively select where result table would look like this. select * from #table where id=3 id int | parent int | value string | depth -------------------------------------------------------- 3 2 some3

Iterating over an N-dimensional matrix with variable dimension sizes in C++

China☆狼群 提交于 2020-01-04 01:12:13
问题 I am trying to iterate over an n-dimensional matrix where each dimension of the matrix also has a variable size. I specifically want to have each elements multi-dimensional coordinate, like a for loop gives you i to access an element in an array. I want to basically re-create a nested for loop like the following code with recursion where I could put any different kind of numbers into dimensionSize . std::vector<int> dimensionSize = {1, 4, 4}; for (int i = 0; i < dimensionSize [0]; i++) { for

Javascript recursive timeout call

左心房为你撑大大i 提交于 2020-01-03 21:18:09
问题 This is my attempt at writing a dynamic onmouseout event that slowly changes the opacity when the mouse leaves the div. For some reason the recursion and timeout seem to be no working property and the change in opacity is done immediately. The question: Is there any reasons that setTimeout() does not work with recursion? Is there a better way to approach this problem? function hide(id) { if (gOpacity > .4) { gOpacity -= .1; document.getElementById(id).style.opacity = gOpacity; setTimeout(hide