Search Results

Search found 1171 results on 47 pages for 'recursive cte'.

Page 11/47 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • SQL: Recursive Path

    - by Chris
    Is it possible to create a "tree resolver" in SQL? I have a table: ID Name Parent 1 a 2 b 1 3 c 1 4 d 3 Now I want a SQL query that returns: ID PATH 1 /a 2 /a/b 3 /a/c 4 /a/c/d Is this possible with SQL? It would make many things easier for me. Any help would really be appreciated!

    Read the article

  • Using lock(obj) inside a recursive call

    - by Amby
    As per my understanding a lock is not released until the runtime completes the code block of the lock(obj) ( because when the block completes it calls Monitor.Exit(obj). With this understanding i am not able to understand the reason behind the behaviour of the following code. private static string obj = ""; private static void RecurseSome(int number) { Console.WriteLine(number); lock (obj) { RecurseSome(++number); } } //Call: RecurseSome(0) //Output: 0 1 2 3...... stack overflow exception There must be some concept that i am missing. Please help.

    Read the article

  • passing self data into a recursive function

    - by user272689
    I'm trying to set a function to do something like this def __binaryTreeInsert(self, toInsert, currentNode=getRoot(), parentNode=None): where current node starts as root, and then we change it to a different node in the method and recursivly call it again. However, i cannot get the 'currentNode=getRoot()' to work. If i try calling the funcion getRoot() (as above) it says im not giving it all the required variables, but if i try to call self.getRoot() it complains that self is an undefined variable. Is there a way i can do this without having to specify the root while calling this method?

    Read the article

  • Recursive wildcards in Rake?

    - by Roger Lipscombe
    Follow up to this question about GNU make: I've got a directory, flac, containing .FLAC files. I've got a corresponding directory, mp3 containing MP3 files. If a FLAC file is newer than the corresponding MP3 file (or the corresponding MP3 file doesn't exist), then I want to run a bunch of commands to convert the FLAC file to an MP3 file, and copy the tags across. The kicker: I need to search the flac directory recursively, and create corresponding subdirectories in the mp3 directory. The directories and files can have spaces in the names, and are named in UTF-8. It turns out that this won't work in make, because of the spaces in the directories and filenames, so I'm wondering how to do it in rake instead...

    Read the article

  • Segmentation fault in C recursive Combination (nCr)

    - by AruniRC
    PLease help me out here. The program is supposed to recursively find out the combination of two numbers. nCr = n!/ (r!(n-r)! ). I'm getting this error message when i compile it on GCC. Here's what the terminal shows: Enter two numbers: 8 4 Segmentation fault (Program exited with code:139) The code is given here: #include<stdio.h> float nCr(float, float, float); int main() { float a, b, c; printf("Enter two numbers: \n"); scanf("%f%f", &a, &b); c = nCr(a, b, a-b); printf("\n%.3f", c); return 0; } float nCr(float n, float r, float p) { if(n<1) return (1/(p*r))*(nCr(1, r-1, p-1)); if(r<1) return (n/(p*1))*(nCr(n-1, 1, p-1)); if(p<1) return (n/r)*(nCr(n-1, r-1, 1)); return ( n/(p*r) )*nCr(n-1, r-1, p-1); }

    Read the article

  • Recursive COUNT Query (SQL Server)

    - by Cosmo
    Hello Guys! I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories. Category Id : bigint (PK) Name : nvarchar(255) AcceptQuestions : bit IdParent : bigint (FK) Question Id : bigint (PK) Title : nvarchar(255) ... IdCategory : bigint (FK) How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(

    Read the article

  • Recursive COUNT Query (MS SQL)

    - by Cosmo
    Hello Guys! I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories. Category Id : bigint (PK) Name : nvarchar(255) AcceptQuestions : bit IdParent : bigint (FK) Question Id : bigint (PK) Title : nvarchar(255) ... IdCategory : bigint (FK) How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(

    Read the article

  • constructing a recursive function returning an array

    - by Admiral Kunkka
    I'm developing a function that has a random chance to loop through itself and put it's results in one array for me to use later in my PHP class. Is there a better way to do this more organized, specifically case 5. The array becomes sloppy if it rolls 5, after 5, after 5 looking unpleasant. private function dice($sides) { return mt_rand(1, $sides); } private function randomLoot($dice) { switch($dice) { case 1: $array[] = "A fancy mug."; break; case 2: $array[] = "A buckler."; break; case 3: $array[] = "A sword."; break; case 4: $array[] = "A jewel."; break; case 5: $array[] = "A treasure chest with contents:"; $count = $this->dice(3); $i = 1; while($i <= $count) { $array[] = $this->randomLoot($this->dice(5)); $i++; } break; } return $array; }

    Read the article

  • Find a base case for a recursive void method

    - by Evan S
    I am doing homework. I would like to build a base case for a recursion where ordering given numbers (list2) in ascending order. Purpose of writing this codes is that when all numbers are in ascending order then should stop calling a method called ascending(list2, list1); and all values in list2 should be shipped to list1. For instance, list2 = 6,5,4,3,2,1 then list2 becomes empty and list1 should be 1,2,3,4,5,6. I am trying to compare result with previous one and if matches then stop. But I can't find the base case to stop it. In addition, Both ascending() and fixedPoint() are void method. Anybody has idea? lol Took me 3 days... When I run my code then 6,5,4,3,2,1 5,6,4,3,2,1 4,5,6,3,2,1 3,4,5,6,2,1 2,3,4,5,6,1 1,2,3,4,5,6 1,2,3,4,5,6 1,2,3,4,5,6 1,2,3,4,5,6 1,2,3,4,5,6 infinite............. public class Flipper { public static void main(String[] args) { Flipper aFlipper = new Flipper(); List<Integer> content = Arrays.asList(6,5,4,3,2,1); ArrayList<Integer> l1 = new ArrayList<Integer>(content); ArrayList<Integer> l2 = new ArrayList<Integer>(); // empty list aFlipper.fixedPoint(l2,l1); System.out.println("fix l1 is "+l1); System.out.println("fix l2 is "+l2); } public void fixedPoint(ArrayList<Integer> list1, ArrayList<Integer> list2) { // data is in list2 ArrayList<Integer> temp1 = new ArrayList<Integer>(); // empty list if (temp1.equals(list2)) { System.out.println("found!!!"); } else { ascending(list2, list1); // data, null temp1 = list1; // store processed value System.out.println("st list1 is "+list1); System.out.println("st list2 is "+list2); } fixedPoint(list2, list1); // null, processed data }

    Read the article

  • Recursive powerof-function, see if you can solve it

    - by Jonas B
    First of all, this is not schoolwork - just my curiousity as I for some reason can't get my head around it and solve it. I come up with these stupid things all the time and it annoys the hell out of me when I cant solve them. Code example is in C# but solution doesn't have to be in any particular programming-language. long powerofnum(short num, long powerof) { return powerofnum2(num, powerof, powerof); } long powerofnum2(short num, long powerof, long holder) { if (num == 1) return powerof; else { return powerof = powerofnum2(num - 1, holder * powerof, holder); } } As you can see I have two methods. I call for powerofnum(value, powerofvalue) which then calls the next method with the powerofvalue also in a third parameter as a placeholder so it remembers the original powerof value through the recursion. What I want to accomplish is to do this with only one method. I know I could just declare a variable in the first method with the powerof value to remember it and then iterate from 0 to value of num. But as this is a theoretical question I want it done recursively. I could also in the first method just take a third parameter called whatever to store the value just like I do in the second method that is called by the first, but that looks really stupid. Why should you have to write what seems like the same parameter twice? Rules explained in short: no iteration scope-specific variables only only one method Anyhow, I'd appreciate a clean solution. Good luck :)

    Read the article

  • Adding some delay in an recursive loop and breaking out of it on mouseover

    - by Moak
    I have created a loop function loopThem(){ $$('#main-nav a').each(function(i, n) { i.up("#main-nav").down("li.active").removeClassName("active"); i.up("li").addClassName("active"); var target = i.readAttribute("href"); i.up(".home-top").down("li.visible").removeClassName("visible"); i.up(".home-top").down(target).addClassName("visible"); }); loopThem(); } This function is called when the dom is loaded document.observe("dom:loaded", function() { loopThem(); }); It does what I want as far as rotating through a set of banners, however it does so at light speed How Can I A add a delay between the changing? B stop the loop from continuing once I mouse over?

    Read the article

  • Recursive templates: compilation error under g++

    - by Johannes
    Hi, I am trying to use templates recursively to define (at compile-time) a d-tuple of doubles. The code below compiles fine with Visual Studio 2010, but g++ fails and complains that it "cannot call constructor 'point<1::point' directly". Could anyone please shed some light on what is going on here? Many thanks, Jo #include <iostream> #include <utility> using namespace std; template <const int N> class point { private: pair<double, point<N-1> > coordPointPair; public: point() { coordPointPair.first = 0; coordPointPair.second.point<N-1>::point(); } }; template<> class point<1> { private: double coord; public: point() { coord= 0; } }; int main() { point<5> myPoint; return 0; }

    Read the article

  • Recursive Enumeration in Java

    - by Harm De Weirdt
    Hello everyone. I still have a question about Enumerations. Here's a quick sketch of the situation. I have a class Backpack that has a Hashmap content with as keys a variable of type long, and as value an ArrayList with Items. I have to write an Enumeration that iterates over the content of a Backpack. But here's the catch: in a Backpack, there can also be another Backpack. And the Enumeration should also be able to iterate over the content of a backpack that is in the backpack. (I hope you can follow, I'm not really good at explaining..) Here is the code I have: public Enumeration<Object> getEnumeration() { return new Enumeration<Object>() { private int itemsDone = 0; //I make a new array with all the values of the HashMap, so I can use //them in nextElement() Collection<Long> keysCollection = getContent().keySet(); Long [] keys = keysCollection.toArray(new Long[keysCollection.size()]); public boolean hasMoreElements() { if(itemsDone < getContent().size()) { return true; }else { return false; } } public Object nextElement() { ArrayList<Item> temporaryList= getContent().get(keys[itemsDone]); for(int i = 0; i < temporaryList.size(); i++) { if(temporaryList.get(i) instanceof Backpack) { return temporaryList.get(i).getEnumeration(); }else { return getContent().get(keys[itemsDone++]); } } } }; Will this code work decently? It's just the "return temporaryList.get(i).getEnumeration();" I'm worried about. Will the users still be able to use just the hasMoreElemens() and nextElement() like he would normally do? Any help is appreciated, Harm De Weirdt

    Read the article

  • Javascript recursive data structure definition

    - by Matt Bierner
    I need to define a data structure recursively in Javascript. Here is a simple example of a circular linked list: // List a very simplified example of what the actual (non list) code does. function List(f, r) { return function(){ return [f, r]; }; } var head = List('a', List('b', List('c', head))); When this is executed, head in List 'c' is resolved to undefined, not List 'a' as I need. List is an example function that returns a function (It is not an Javascript list that I can append to). I tried to wrap the definition of head is a self executing named function, but that blew the stack when head was resolved. What is the Javascript style solution that I am overlooking?

    Read the article

  • Recursive Iterators

    - by soandos
    I am having some trouble making an iterator that can traverse the following type of data structure. I have a class called Expression, which has one data member, a List<object>. This list can have any number of children, and some of those children might be other Expression objects. I want to traverse this structure, and print out every non-list object (but I do want to print out the elements of the list of course), but before entering a list, I want to return "begin nest" and after I just exited a list, I want to return "end nest". I was able to do this if I ignored the class wherever possible, and just had List<object> objects with List<object> items if I wanted a subExpression, but I would rather do away with this, and instead have an Expressions as the sublists (it would make it easier to do operations on the object. I am aware that I could use extension methods on the List<object> but it would not be appropriate (who wants an Evaluate method on their list that takes no arguments?). The code that I used to generate the origonal iterator (that works) is: public IEnumerator GetEnumerator(){ return theIterator(expr).GetEnumerator(); } private IEnumerable theIterator(object root) { if ((root is List<object>)){ yield return " begin nest "; foreach (var item in (List<object>)root){ foreach (var item2 in theIterator(item)){ yield return item2; } } yield return " end nest "; } else yield return root; } A type swap of List<object> for expression did not work, and lead to a stackOverflow error. How should the iterator be implemented? Update: Here is the swapped code: public IEnumerator GetEnumerator() { return this.GetEnumerator(); } private IEnumerable theIterator(object root) { if ((root is Expression)) { yield return " begin nest "; foreach (var item in (Expression)root) { foreach (var item2 in theIterator(item)) yield return item2; } yield return " end nest "; } else yield return root; }

    Read the article

  • Nested <ul><li> navigation menu using a recursive Python function

    - by Alex
    Hi. I want to render this data structure as an unordered list. menu = [ [1, 0], [2, 1], [3, 1], [4, 3], [5, 3], [6, 5], [7,1] ] [n][0] is the key [n][1] references the parent key The desired output is: <ul> <li>Node 1</li> <ul> <li>Node 2</li> <li>Node 3</li> <ul> <li>Node 4</li> <li>Node 5</li> <ul> <li>Node 6</li> </ul> </ul> <li>Node 7</li> </ul> </ul> I could probably do this without recursion but that would be no fun. Unfortunately, I am having problems putting it all together. I don't have much experience with recursion and this is proving to be very difficult for me to build and debug. What is the most efficient way to solve this problem in Python? Thanks!

    Read the article

  • t-sql help with recursive sort of query

    - by stackoverflowuser
    Hi Based on the following table ID Path --------------------------------------- 1 \\Root 2 \\Root\Node0 3 \\Root\Node0\Node1 4 \\Root\Node0\Node2 5 \\Root\Node3 6 \\Root\Node3\Node4 7 \\Root\Node5 ... N \\Root\Node5\Node6\Node7\Node8\Node9\Node10 so on... There are around 1000 rows in this table. I want to display individual node in seperate columns. Maximum columns to be displayed 5 (i.e. node till 5 level deep). So the output will look as below ID Path Level 0 Level 1 Level 2 Level 3 Level 4 Level 5 ---------------------------------------------------------------------------------------- 1 \\Root Root Null Null Null Null Null 2 \\Root\Node0 Root Node 0 Null Null Null Null 3 \\Root\Node0\Node1 Root Node 0 Node 1 Null Null Null 4 \\Root\Node0\Node2 Root Node 0 Node 2 Null Null Null 5 \\Root\Node3 Root Node 3 Null Null Null Null 6 \\Root\Node3\Node4 Root Node 3 Node 4 Null Null Null 7 \\Root\Node5 Root Node 5 Null Null Null Null ... N (see in above table) Root Node 5 Node 6 Node 7 Node 8 Node 9 The only way i can think of is to open a cursor, loop through each row and perform string split, just fetch the first 5 nodes and then insert into a temp table. Pls. suggest. Thanks

    Read the article

  • Implementing a recursive menu system a'la Joomla in CodeIgniter

    - by pettersolberg
    Hi I have some sites powered by Joomla, but with my current assignment I wanted to try something new and created with CodeIgniter a really basic CMS (just to suit my client's needs). Everything works fine except menus - multilevel menus like in Joomla, Drupal etc. with items and subitems... My question is: do you know of any tutorials or texts abut implementing such a structure. I've tried the recursion thinggy with while getting children's IDs move downwards from the parent while searching for the currently displayed item's ID. I've tried also the Drupalish way with having a path parameter enclosing ID's all the way from top to bottom '1/23/123/3'. But all in all it was just too chaotic - code something, try it out. If you have some idea on this topic - thanks in advice.

    Read the article

  • Find the right value in recursive array

    - by fire
    I have an array with multiple sub-arrays like this: Array ( [0] => Array ( [Page_ID] => 1 [Page_Parent_ID] => 0 [Page_Title] => Overview [Page_URL] => overview [Page_Type] => content [Page_Order] => 1 ) [1] => Array ( [0] => Array ( [Page_ID] => 2 [Page_Parent_ID] => 1 [Page_Title] => Team [Page_URL] => overview/team [Page_Type] => content [Page_Order] => 1 ) ) [2] => Array ( [Page_ID] => 3 [Page_Parent_ID] => 0 [Page_Title] => Funds [Page_URL] => funds [Page_Type] => content [Page_Order] => 2 ) [3] => Array ( [0] => Array ( [Page_ID] => 4 [Page_Parent_ID] => 3 [Page_Title] => Strategy [Page_URL] => funds/strategy [Page_Type] => content [Page_Order] => 1 ) [1] => Array ( [0] => Array ( [Page_ID] => 7 [Page_Parent_ID] => 4 [Page_Title] => A Class Fund [Page_URL] => funds/strategy/a-class-fund [Page_Type] => content [Page_Order] => 1 ) [1] => Array ( [0] => Array ( [Page_ID] => 10 [Page_Parent_ID] => 7 [Page_Title] => Information [Page_URL] => funds/strategy/a-class-fund/information [Page_Type] => content [Page_Order] => 1 ) [1] => Array ( [Page_ID] => 11 [Page_Parent_ID] => 7 [Page_Title] => Fund Data [Page_URL] => funds/strategy/a-class-fund/fund-data [Page_Type] => content [Page_Order] => 2 ) ) [2] => Array ( [Page_ID] => 8 [Page_Parent_ID] => 4 [Page_Title] => B Class Fund [Page_URL] => funds/strategy/b-class-fund [Page_Type] => content [Page_Order] => 2 ) I need a function to find the right Page_URL so if you know the $url is "funds/strategy/a-class-fund" I need to pass that to a function that returns a single array result (which would be the Page_ID = 7 array in this example). Having a bit of a stupid day, any help would be appreciated!

    Read the article

  • Recursive search Linq to xml

    - by Raj Esh
    this is my sample xml. <Messages> <Conversation> <id>Z100</id> <ReplyToId></ReplyToId> <Message>Topic</Message> </Conversation> <Conversation> <id>A100</id> <ReplyToId></ReplyToId> <Message>This is a test</Message> </Conversation> <Conversation> <id>M100</id> <ReplyToId>A100</ReplyToId> <Message>What kind of test</Message> </Conversation> <Conversation> <id>A200</id> <ReplyToId>M100</ReplyToId> <Message>Stage 1</Message> </Conversation> <Conversation> <id>M200</id> <ReplyToId>A200</ReplyToId> <Message>Test result for </Message> </Conversation> </Messages> How to get the conversation list based on id using linq in C#. Say for example, If i want to get the conversation for id "A100" which has a link to other conversation based on ReplyToid.

    Read the article

  • how to exit recursive math formula and still get an answer

    - by calccrypto
    i wrote this python code, which from wolfram alpha says that its supposed to return the factorial of any positive value (i probably messed up somewhere), integer or not: from math import * def double_factorial(n): if int(n) == n: n = int(n) if [0,1].__contains__(n): return 1 a = (n&1) + 2 b = 1 while a<=n: b*=a a+= 2 return float(b) else: return factorials(n/2) * 2**(n/2) *(pi/2)**(.25 *(-1+cos(n * pi))) def factorials(n): return pi**(.5 * sin(n*pi)**2) * 2**(-n + .25 * (-1 + cos(2*n*pi))) * double_factorial(2*n) the problem is , say i input pi to 6 decimal places. 2*n will not become a float with 0 as its decimals any time soon, so the equation turns out to be pi**(.5 * sin(n*pi)**2) * 2**(-n + .25 * (-1 + cos(2*n*pi))) * double_factorial(loop(loop(loop(...))))) how would i stop the recursion and still get the answer? ive had suggestions to add an index to the definitions or something, but the problem is, if the code stops when it reaches an index, there is still no answer to put back into the previous "nests" or whatever you call them

    Read the article

  • Problem with a recursive function to find sqrt of a number

    - by Eternal Learner
    Below is a simple program which computes sqrt of a number using Bisection. While executing this with a call like sqrtr(4,1,4) in goes into an endless recursion . I am unable to figure out why this is happening. Below is the function : double sqrtr(double N , double Low ,double High ) { double value = 0.00; double mid = (Low + High + 1)/2; if(Low == High) { value = High; } else if (N < mid * mid ) { value = sqrtr(N,Low,mid-1) ; } else if(N >= mid * mid) { value = sqrtr(N,mid,High) ; } return value; }

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >