recursion

C++: Duplicating a tree of derived elements

独自空忆成欢 提交于 2020-02-25 13:06:05
问题 I have a base class and several derived classes. The base class looks like this: class Base { int type; //the derived type the object belongs to int nOfChildren; Base** children; //each child can be any of the derived types ... } Now I need to duplicate an instance of Base . Because of the recursion, a virtual method Base::duplicate() is needed. It also seems clear what should go in it: Base temp = new Base(); temp->type = temp; temp->nOfChildren = nOfChildren; temp->children = new Base*

Get all combinations for arbitrary number of elements

痞子三分冷 提交于 2020-02-25 04:49:10
问题 How can I make a method in Java which obtains input integer n , and an array of double x , and returns all combinations of n elements out of values in x. Where x={1,2,3} and n=2, the expected returns/combinations are {1,1},{1,2},{1,3},{2,2},{2,1},{2,3},{3,1},{3,2},{3,3} (the order is not ignored.) The number should be (int) Math.pow(x.length, n) e.g. static List<Double[]> getAll(int n, double[] x){ List<Double[]> combinations = new ArrayList<>(); //number of combinations should be x.length ^

Recursive File Search in VB.NET

三世轮回 提交于 2020-02-25 04:44:52
问题 I have a function that does a recursive directory search for files but when I search a Drive I get Access denied errors which stops the search. How can I avoid these errors? Here's the function I use: lstSearch = GetFilesRecursive(FolderBrowserDialogMain.SelectedPath) Private Function GetFilesRecursive(ByVal path As String) As List(Of String) Dim lstResult As New List(Of String) Dim stkStack As New Stack(Of String) stkStack.Push(path) Do While (stkStack.Count > 0) Dim strDirectory As String =

Recursive File Search in VB.NET

萝らか妹 提交于 2020-02-25 04:42:11
问题 I have a function that does a recursive directory search for files but when I search a Drive I get Access denied errors which stops the search. How can I avoid these errors? Here's the function I use: lstSearch = GetFilesRecursive(FolderBrowserDialogMain.SelectedPath) Private Function GetFilesRecursive(ByVal path As String) As List(Of String) Dim lstResult As New List(Of String) Dim stkStack As New Stack(Of String) stkStack.Push(path) Do While (stkStack.Count > 0) Dim strDirectory As String =

Recursive File Search in VB.NET

。_饼干妹妹 提交于 2020-02-25 04:42:00
问题 I have a function that does a recursive directory search for files but when I search a Drive I get Access denied errors which stops the search. How can I avoid these errors? Here's the function I use: lstSearch = GetFilesRecursive(FolderBrowserDialogMain.SelectedPath) Private Function GetFilesRecursive(ByVal path As String) As List(Of String) Dim lstResult As New List(Of String) Dim stkStack As New Stack(Of String) stkStack.Push(path) Do While (stkStack.Count > 0) Dim strDirectory As String =

How to implement recursive search filter in agngulrjs?

风格不统一 提交于 2020-02-25 04:20:41
问题 There is a multi level java script object.Then I print these object using ng-repeat recursively.Now I filter the nodes.When I give the search string it only shows the matching string.But what I am looking for is it should filter along with its parent tree.Example if I search for keyword "self" then there are two nodes having "Self" keyword.They are Pateint: Self D or DA: Self / Care team And their parent is Step 1: User types allowed to access and it's parent is Access details and it's parent

Recursive method for palindrome checkup

99封情书 提交于 2020-02-24 10:17:25
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str

Recursive method for palindrome checkup

牧云@^-^@ 提交于 2020-02-24 10:15:55
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str

Recursive method for palindrome checkup

我是研究僧i 提交于 2020-02-24 10:15:26
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str

Recursive method for palindrome checkup

烂漫一生 提交于 2020-02-24 10:15:14
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str