recursion

Why would this simple code cause a stack overflow exception?

♀尐吖头ヾ 提交于 2019-12-25 18:29:15
问题 The stack overflow exception was thrown in the setter method of this property: public string TimeZone { get { if (TimeZone == null) return ""; return TimeZone; } set { TimeZone = value; } } "An unhandled exception of type 'System.StackOverflowException' occurred" I do not see any straightforward recursion here. If there are problems with the code, what should I be using instead to correct it? 回答1: set { TimeZone = value; } The setter is recursive. You must use a field like: string _timeZone;

How to create a 2d list with all same values but can alter multiple elements within? (python)

牧云@^-^@ 提交于 2019-12-25 18:17:22
问题 I'm trying to create a list that holds this exact format: [[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]] and when list[3][0] = 9 is called, the list becomes [[2],[9],[2],[9],[2],[9],[2],[9],[2],[9]] How do I create the list in the first place that will allow me to change these many elements with only one line? 回答1: >>> L = [[2], [2]] * 5 >>> L [[2], [2], [2], [2], [2], [2], [2], [2], [2], [2]] >>> L[3][0] = 9 >>> L [[2], [9], [2], [9], [2], [9], [2], [9], [2], [9]] This is because the same two

Recursive backtracking help!

匆匆过客 提交于 2019-12-25 18:17:04
问题 I'm in abit of a pickle. I've got to implement a recursive backtracking algorithm that will work out how to cut a bar with the least ammount of wasteage. this is from the specification for the coursework. Quote: Now, imagine the scenario in which a factory manufactures steel bars of length 150mm. Its cutting shop receives orders for cut lengths of bars, which must be met by cutting up the manufactured bars. With each order the factory wants to cut the bar is such a way that it produces the

Recursive parsing of JSON object to construct HTML elements

北战南征 提交于 2019-12-25 18:16:57
问题 I'm attempting to build a set of HTML elements from a JSON object. I've managed to successfully construct the object from HTML elements, but the recursive rebuild keeps failing on me. Anyone have a good solution? My JSON: { "0": { "id": "text-1", "tag": "div", "style": { "left": "92px", "top": "37px", "z-index": "3", "height": "19px", "width": "98px", "font-weight": "bold", "font-style": "italic", "font-size": "16px", "color": "rgb(255, 255, 255)" }, "data": {}, "children": { "0": { "tag":

Recursive backtracking help!

淺唱寂寞╮ 提交于 2019-12-25 18:16:14
问题 I'm in abit of a pickle. I've got to implement a recursive backtracking algorithm that will work out how to cut a bar with the least ammount of wasteage. this is from the specification for the coursework. Quote: Now, imagine the scenario in which a factory manufactures steel bars of length 150mm. Its cutting shop receives orders for cut lengths of bars, which must be met by cutting up the manufactured bars. With each order the factory wants to cut the bar is such a way that it produces the

Number of loops in recursion

只谈情不闲聊 提交于 2019-12-25 17:25:54
问题 I would like to count the number of positive integers/elements in the list. This returns the elements with positive values, how can I count the elements? would like to construct something like count(array(...)). I would like to see a version with i++ and foldl . That would be very helpful. countPositivesRec :: [Int] -> [Int] countPositivesRec [] = [] countPositivesRec (x:xs) | x >= 0 = x : tl | otherwise = tl where tl = countPositivesRec xs 回答1: Here's a hint: follow the same recursion scheme

Can I nest a composite component in itself recursively?

回眸只為那壹抹淺笑 提交于 2019-12-25 17:03:10
问题 I have DTO which contains itself (it is nested). public class MyDTO { private SomeData someData; private MyDTO nested; // getters and setters } I created composite component, which is calls itself recursively. I call it like this: <screen:my-dto-screen dto="#{myDTOBean.myDto}" /> The definition is: <composite:interface> <composite:attribute name="dto"/> </composite:interface> -- display "someData" here -- <p:panel rendered="#{cc.attrs.dto.nested != null}" /> -- this acts as recursion bottom -

divide list using recursion

梦想的初衷 提交于 2019-12-25 16:55:43
问题 I am trying to implement this function using recursion, the function takes a function parameter f where when passed a value it will return as true or false. It should check all values in the list and store all true values in a list and false values in another list returning them in a tuple. def divL(f, l): if not l: return ([],[]) else: a = list() b = list() for i in range(len(l)): if f(l[i]): a.append(l[i]) else: b.append(l[i]) return (a, b) 回答1: Recursive version. But I agree with others

How to write a “which day is it after x days” recursion in Haskell?

三世轮回 提交于 2019-12-25 16:55:39
问题 I am starting to learn Haskell and I'm trying to get this code to work but I cannot understand where is my mistake. I would really appreciate it if you could explain it to me. :) I want to type for example Mon 8 and get Tue. data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun < - [1..7] next :: Day -> Day next Mon = Tue next Tue = Wed next Wed = Thu next Thu = Fri next Fri = Sat next Sat = Sun next Sun = Mon gez n :: (Ord a) => a -> a -> Bool | n > 7 = n - 7 | n <= 7 = n 回答1: You don't have

SQL - Recursive Tree Hierarchy with Record at Each Level

混江龙づ霸主 提交于 2019-12-25 12:25:08
问题 Trying to do a classic hierarchy tree in SQL, using SAS (which does not support WITH RECURSIVE, so far as I know). Here's simplified data structure in existing table: |USER_ID|SUPERVISOR_ID| So, to build a hierarchy, you just recursively join it x number of times to get data you are looking for, where SUPERVISOR_ID = USER_ID . In my company, it is 16 levels. This issue comes when trying to get a branch to terminate for each user. For example, let's consider User A at level 1 has Users B,C,D,