recursion

Recursive Query for Bill Of Materials

╄→гoц情女王★ 提交于 2019-12-29 07:14:32
问题 I've just started teaching myself SQL recently and have been able to piece together almost everything I need from various tutorials, but this one has me banging my head against the wall. We have a table that contains all the bill of material information for our products. I only need 4 of the columns from it - PPN_I, CPN_I, QUANTITY_I, BOMNAME_I - which are Item Number, Raw Material number, quantity, and the BOMName, respectively. Many of the BOMs contain subassemblies. I need a result set

Recursion and Iteration

我怕爱的太早我们不能终老 提交于 2019-12-29 07:08:09
问题 What is the difference? Are these the same? If not, can someone please give me an example? MW: Iteration - 1 : the action or a process of iterating or repeating: as a : a procedure in which repetition of a sequence of operations yields results successively closer to a desired result b : the repetition of a sequence of computer instructions a specified number of times or until a condition is met Recusion - 3 : a computer programming technique involving the use of a procedure, subroutine,

How to list all properties exposed by a Java class and its ancestors in Eclipse?

你。 提交于 2019-12-29 06:47:12
问题 Given a single Java class I'd like to be able to list all properties that are exposed in all ancestors and recursively traverse all their exposed properties (i.e. public or with getters/setters) in the same way. Easier to explain with a simple example: public class BaseClass1 { private int intProperty; // has getter and setter (not shown) } public class SubClass1 extends BaseClass1 { private int privateSoNotListed; public SubClass2 subClass2Property; } public class BaseClass2 { public String

How would you write a non-recursive algorithm to calculate factorials?

孤街醉人 提交于 2019-12-29 06:42:27
问题 How would you write a non-recursive algorithm to compute n! ? 回答1: Since an Int32 is going to overflow on anything bigger than 12! anyway, just do: public int factorial(int n) { int[] fact = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600}; return fact[n]; } 回答2: in pseudocode ans = 1 for i = n down to 2 ans = ans * i next 回答3: public double factorial(int n) { double result = 1; for(double i = 2; i<=n; ++i) { result *= i; } return result; } 回答4: In the interests

Recursive lambda callbacks without Y Combinator

梦想与她 提交于 2019-12-29 06:25:15
问题 I wish to create a callback that recursively returns itself as a callback. The suggested method to recurse is for the function to have a reference to itself: std::function<void (int)> recursive_function = [&] (int recurse) { std::cout << recurse << std::endl; if (recurse > 0) { recursive_function(recurse - 1); } }; This fails as soon as you return it from a function: #include <functional> #include <iostream> volatile bool no_optimize = true; std::function<void (int)> get_recursive_function()

Create a triangle out of stars using only recursion

牧云@^-^@ 提交于 2019-12-29 06:17:03
问题 I need to to write a method that is called like printTriangle(5); . We need to create an iterative method and a recursive method (without ANY iteration). The output needs to look like this: * ** *** **** ***** This code works with the iterative but I can't adapt it to be recursive. public void printTriangle (int count) { int line = 1; while(line <= count) { for(int x = 1; x <= line; x++) { System.out.print("*"); } System.out.print("\n"); line++; } } I should note that you cannot use any class

Create a triangle out of stars using only recursion

末鹿安然 提交于 2019-12-29 06:16:32
问题 I need to to write a method that is called like printTriangle(5); . We need to create an iterative method and a recursive method (without ANY iteration). The output needs to look like this: * ** *** **** ***** This code works with the iterative but I can't adapt it to be recursive. public void printTriangle (int count) { int line = 1; while(line <= count) { for(int x = 1; x <= line; x++) { System.out.print("*"); } System.out.print("\n"); line++; } } I should note that you cannot use any class

Compilation Error on Recursive Variadic Template Function

我们两清 提交于 2019-12-29 06:16:12
问题 I've prepared a simple variadic template test in Code::Blocks, but I'm getting an error: No matching function for call to 'OutputSizes()' Here's my source code: #include <iostream> #include <typeinfo> using namespace std; template <typename FirstDatatype, typename... DatatypeList> void OutputSizes() { std::cout << typeid(FirstDatatype).name() << ": " << sizeof(FirstDatatype) << std::endl; OutputSizes<DatatypeList...>(); } int main() { OutputSizes<char, int, long int>(); return 0; } I'm using

Recursive function for trees in Python

谁都会走 提交于 2019-12-29 06:15:30
问题 I'm trying to make a function in Python, that takes an arbitrary node of a tree, and populates a list of lists based on the node give. Given the following badly drawn tree: If we start at, for example, node 5, we should get: A list containing all nodes with the same parent node, including the one we started at (4 and 5) Any child nodes, but not their children (6). Parent nodes and any parent nodes with the same parent, and their parent's nodes, etc. until we get to the root node, but not

Recursive function for trees in Python

梦想的初衷 提交于 2019-12-29 06:14:46
问题 I'm trying to make a function in Python, that takes an arbitrary node of a tree, and populates a list of lists based on the node give. Given the following badly drawn tree: If we start at, for example, node 5, we should get: A list containing all nodes with the same parent node, including the one we started at (4 and 5) Any child nodes, but not their children (6). Parent nodes and any parent nodes with the same parent, and their parent's nodes, etc. until we get to the root node, but not