recursion

copy folder, subfolders and files from a path to another path in python via a recursive function

徘徊边缘 提交于 2019-12-24 07:59:35
问题 I want to copy some folders and files from a path to another path. for example, I want to copy the folder(called folder1) which has some other subfolders and some files inside itself to another folder(dst). In my program, at the first, I want to check if there is a folder named folder1 in destination folder and if not, create a folder with folder1 name and then copy the content of folder1 to target. In addition, maybe we have folder1 in the target path, but there are some subfolders of

JSON data into HTML list that looks like a table

混江龙づ霸主 提交于 2019-12-24 07:37:12
问题 Have nested JSON array and currently trying to create a HTML list ul/li type that also resembles a table. Here is my JSON data, questions is name of object. { "aaData": [ { "id": "1", "template_id": "1", "question": "Is government stable?", "answer": "Stable", "parent_question_id": "0", "section_id": "2", "subquestions": [ { "id": "2", "template_id": "1", "question": "Is there funding approved?", "answer": "Since March 2013", "parent_question_id": "1", "section_id": "2", "subquestions": [ {

How to recursively walk through a directory and print all files in C?

早过忘川 提交于 2019-12-24 07:25:29
问题 I am trying to recursively walk through a directory and print out all of the files. When I try doing it with the code below, for example I call the function with sprint(".", ".") I get an output of a bunch of dots. When I reduce the amount of open processes allowed (ulimit -n 20) I get 17 dots. I don't understand though because I thought readdir() and opendir() doesn't make new processes. Here is my code: void sprint(char *filename, char * dirToOpen) { DIR *directory = opendir(dirToOpen);

Bad memory management? Class member (boolean) value greater than 1, in recursion function

孤人 提交于 2019-12-24 07:15:22
问题 I am working on a subgraph matching problem (match chemical functional groups within molecules). The original code was written by another student (under Visual C++, no MS specific libraries) and it ran fine on Windows . I then added new functions to the program but did not alter the algorithm for the subgraph matching, and the new program compiled fine under gcc4.2/Mac OS X. However I am running into strange problems during runtime! The objects & their members that are relevant here: Atom:

Return value of function in C

℡╲_俬逩灬. 提交于 2019-12-24 07:09:20
问题 int ret(char *) { //nothing } int main(void) { printf("%d\n",ret("foo")); } Why does the Function ret returns a garbage value ??? and int my_strlen(char *s) { if(*s) return 1 + my_strlen(s + 1); // or my_strlen(s+1) + 1; } in the above function , if i am not wrong , my_strlen should always return Junk value when condition fails (i.e whenever it reaches to '\0') as there is no else case or any return statement for false case. So for any valid string it should always return 1 + junk value. But

Sum of Digits using recursion in C

孤者浪人 提交于 2019-12-24 07:05:56
问题 For our activity today, we were tasked to make using recursion with the sum of digits. I already made this program: int main() { int num = 0, sum; printf("Enter an integer: "); scanf("%d",&num); //counter=1; for ( sum=0; num>0;) { sum = sum + num % 10; num = num /10; } printf("Sum = %d", sum); getch(); return 0; } Our teacher added "Input and output must be done in the main() function." Am doing the right thing? Or am I missing something in my code? 回答1: To do recursion, create a function

Detecting infinite recursion

江枫思渺然 提交于 2019-12-24 06:28:14
问题 I'm creating a macro for Trac, and one of the things it does is to render a bit of wiki text, that can in turn use the same macro. This can give rise to an infinite recursion if the inner macro is invoked with the same arguments (i.e., renders the same bit of wiki text). I thought of trying to stop the user from shooting his own foot like this by inspecting the call stack and breaking the recursion if the function that expands the macro was already invoked with exactly the same set of

Should/Could this “recursive Task” be expressed as a TaskContinuation?

断了今生、忘了曾经 提交于 2019-12-24 05:54:07
问题 In my application I have the need to continually process some piece(s) of Work on some set interval(s). I had originally written a Task to continually check a given Task.Delay to see if it was completed, if so the Work would be processed that corresponded to that Task.Delay . The draw back to this method is the Task that checks these Task.Delays would be in a psuedo-infinite loop when no Task.Delay is completed. To solve this problem I found that I could create a "recursive Task " (I am not

Reversing a string in c with recursion

徘徊边缘 提交于 2019-12-24 05:50:27
问题 I have written code to reverse a string in c... it works fine but I can't return the reversed string in the main() function. #include<stdio.h> main() { char a[17]="abcdefg"; reverse(a); printf("\n"); system("PAUSE"); } int reverse(char *a) { if(*a!='\0') { reverse(a+1); } printf("%c",*a); } it prints the reversed string but I want the reversed string in main() . How can I do this? 回答1: You need to modify the string, i.e. the input buffer to reverse() , instead of just printing it. Doing this

AVL tree how to balance tree on insert

强颜欢笑 提交于 2019-12-24 05:24:04
问题 I want to make a insert function for a avl tree. However the insert function has to be recursive and must be balanced. I have a method to pivot the tree left PivoterAGauche and a method to pivot the tree right PivoterADroite. 'Pivot left Private Function PivoterAGauche(leNoeud As NoeudAVL) As NoeudAVL If leNoeud Is Nothing Then Return Nothing ElseIf leNoeud.FilsDroit Is Nothing AndAlso leNoeud.FilsGauche Is Nothing Then Return leNoeud ElseIf leNoeud.FilsDroit Is Nothing Then Return leNoeud '