recursion

How do I make a sort method using recursion?

怎甘沉沦 提交于 2019-12-24 12:25:03
问题 I'm learning recursion and I was instructed to make a recursive method that sorts an array. So far I have this: public static void sort(int [] a, int i) { if(i == a.length - 1){ System.out.println(a[i]); } if(i < a.length) { if(a[i] > a[i+1]) { int temp = a[i+1]; a[i+1] = a[i]; a[i] = temp; sort(a,i++); } printArray(a); } } Now I know this is wrong because I still really don't quite understand how to use recursion in my programming. If someone could just help me with the method I would

SSRS: Recursive Parent Child

て烟熏妆下的殇ゞ 提交于 2019-12-24 12:08:57
问题 I want to create hierarchical report in SSRS using this simple table? Could you please help me? I follow the tutorial here: https://www.mssqltips.com/sqlservertip/1939/working-with-a-parent-child-hierarchy-in-sql-server-reporting-services-ssrs/ but I can't figure out how the EmployeeKey and ParentEmployeeKey apply to my table. As far As my table concern Col2 Is the Employee and Col1 is the parent. But in SSRS when I group by Col2 and Recursive Parent is COL1 I don't get the desired result.

Are optional params available for the Compact Framework?

大城市里の小女人 提交于 2019-12-24 12:01:11
问题 I need to get a list of all files on a handheld device whose names fit a certain pattern, such as " ABC .XML" I adapted code from here (Hernaldo's answer), like so: public static List<string> GetXMLFiles(string fileType, string dir) { string dirName = dir; // call it like so: GetXMLFiles("ABC", "\\"); <= I think the double-whack is what I need for Windows CE device...am I right? var fileNames = new List<String>(); try { foreach (string f in Directory.GetFiles(dirName)) { if ((f.Contains

How to create a stored procedure to find cliques in the table of connections between users

一个人想着一个人 提交于 2019-12-24 11:55:22
问题 Loooking for a way to retrieve community from a large dataset I came across an article about the algorithm which seems to be apropriate for large datasets. Anyway the data is stored two tables: users (nodes) and connections and I would like to retrieve the communities by pure sql queries without help of custom applications (I'm using SQL Server 2008). The algorithm to retrieve the cliques is the following: Read the graph G Generate set neighbors(v) for every vertex of G for each vertex v of G

php recursion global variable?

ぃ、小莉子 提交于 2019-12-24 11:50:46
问题 I have a recursion function that parses an object/array with a global variable. If I comment out the global variable I get nothing but if I leave it in it keeps adding to the array other values that should be in it own result set. Do I need to change something here? UPDATE #2: How can I get the return I want, I thought I was pushing all unique values to the array? function getResp($objectPassed) { foreach($objectPassed as $element) { if(is_object($element)) { // recursive call $in_arr =

How can I properly return ArrayList<Object> from recursive method without repeated values?

家住魔仙堡 提交于 2019-12-24 11:43:14
问题 I need a recursive solution which returns any combination of n subset from k set (in mathematical sense). I have an ArrayList and I want return any possible n-size subsets from recursive method. Order doesn't matter. So if I have set of employees {Jim, Tom, Ann, John} and want 2 of them I should get: {Jim Tom}{Jim Ann}{Jim John}{Tom Ann}{Tom John}{Ann John} I found this https://stackoverflow.com/a/16256122/10929764 but it only prints out result. I modified it a bit to add any combination to

Recursive function for an xml file (hierarchial data)

只愿长相守 提交于 2019-12-24 11:35:42
问题 I have an XML file in the following format: <categories> <category id="1"></category> <category id="2"> <category id="3"></category> <category id="4"> <category id="5"></category> </category> </category> </categories> Can anyone please give me some direction on how I might traverse the file using C#? 回答1: First off, System.XML provides some excellent ways to work with XML. I'm assuming you loaded your XML into an XMLDocument, doing so allows you to use XPath Selectors, or just walk through

Stuck on a MIPS recursive function

夙愿已清 提交于 2019-12-24 11:35:11
问题 I'm doing an assignment in MIPS and I feel like my logic is sound but I just can't get the code to produce the correct output. Can anyone look over what I've got and help? This is the corresponding function in C that I'm trying to implement. int function1(int n) { if (n <= 3) { int ans1 = (3*n)-5; return ans1; } else { int ans1 = (n-1)*function1(n-1) + function1(n-2) - n; return ans1; } } This is what I've got in MIPS. For the sample output, when the user enters 8 the output is supposed to be

Import multiple text files to database table cells using PHP

北城以北 提交于 2019-12-24 11:28:35
问题 I'm trying to transfer the contents of multiple text files into a MySQL. These files are sequentially named 1.txt , 2.txt , 3.txt ... 13381.txt . Basically, each file is an HTML document without all the headers, meta, etc. that's been stripped away and only the content is left. I've also made an table with a columns ID and CONTENT . ID is auto-incrementing. I'd like the contents of the files to go into the CONTENT column's cells like this: 1.txt -> row 1 2.txt -> row 2 3.txt -> row 3 etc.

Node.js Stream Timer Recursion

孤者浪人 提交于 2019-12-24 11:27:30
问题 I need to read from a stream when my application goes live, but at the moment, i'm just reading from a normal log file (60000+ JSON documents inside). I will need to read the data received from the last minute(not implemented, since I don't have acess to the stream and can't figure out how to do it), process the data, and ask for more next minute. Any packages or tutorials to help? please Now I'm using a recursion. that every minute calls the start() function, I'm using the setTimeout