Search Results

Search found 1112 results on 45 pages for 'recursive'.

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

  • fastest way to crawl recursive ntfs directories in C++

    - by Peter Parker
    I have written a small crawler to scan and resort directory structures. It based on dirent(which is a small wrapper around FindNextFileA) In my first benchmarks it is surprisingy slow: around 123473ms for 4500 files(thinkpad t60p local samsung 320 GB 2.5" HD). 121481 files found in 123473 milliseconds Is this speed normal? This is my code: int testPrintDir(std::string strDir, std::string strPattern="*", bool recurse=true){ struct dirent *ent; DIR *dir; dir = opendir (strDir.c_str()); int retVal = 0; if (dir != NULL) { while ((ent = readdir (dir)) != NULL) { if (strcmp(ent->d_name, ".") !=0 && strcmp(ent->d_name, "..") !=0){ std::string strFullName = strDir +"\\"+std::string(ent->d_name); std::string strType = "N/A"; bool isDir = (ent->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0; strType = (isDir)?"DIR":"FILE"; if ((!isDir)){ //printf ("%s <%s>\n", strFullName.c_str(),strType.c_str());//ent->d_name); retVal++; } if (isDir && recurse){ retVal += testPrintDir(strFullName, strPattern, recurse); } } } closedir (dir); return retVal; } else { /* could not open directory */ perror ("DIR NOT FOUND!"); return -1; } }

    Read the article

  • Recursive Maze in Java

    - by Api
    I have written a short Java code for solving a simple maze problem to go from S to G. I do not understand where the problem is going wrong. import java.util.Scanner; public class tester { static char [][] grid={ {'.','.'}, {'.','.'}, {'S','G'}, }; static int a=2; static int b=2; static boolean findpath(int x, int y) { if((x > grid.length-1) || (y > grid[0].length-1) || (x < 0 || y < 0)) { return false; } else if(x==a && y==b){ return true; } else if (findpath(x,y-1) == true){ return true; } else if (findpath(x+1,y) == true){ return true; } else if (findpath(x,y+1) == true) { return true; } else if (findpath(x-1,y) == true){ return true; } return false; } public static void main(String[] args){ boolean result=findpath(2,0); System.out.print(result); } } I am giving the starting position directly and goal is defined in a & b. Do help.

    Read the article

  • Recursive problem...

    - by Chronos
    Guys, I'm new to java and multithreading..... and I have a following problem: I have two classes running in two different threads. Class A and Class B. Class A has the method "onNewEvent()". Once that method is invoked, it will ask class B to do some work. As soon as B finishes the work it invokes onJobDone() method of the class A. Now... here comes the problem... what I want is to create new job within onJobDone() method and to send it again to B. here is what I do (pseudo code) ... in the sequence of execution A.onNewEvent(){ //create job //ask B to do it B.do() } B.do{ // Do some stuff A.jobDone() } A.onJobDOne(){ B.do() //doItAgain // print message "Thank you for doing it" } The problem is... that message "Thank you for doing it" never gets printed... in fact, when onJobDone() method is invoked, it invokes B.do()... because B.do() is very fast, it invokes onJobDone() immediatly... so execution flow never comes to PRINT MESSAGE part of code... I suppose this is one of the nasty multithreading problems.... any help would be appreciated.

    Read the article

  • Recursive Binary Search Tree Insert

    - by Nick Sinklier
    So this is my first java program, but I've done c++ for a few years. I wrote what I think should work, but in fact it does not. So I had a stipulation of having to write a method for this call: tree.insertNode(value); where value is an int. I wanted to write it recursively, for obvious reasons, so I had to do a work around: public void insertNode(int key) { Node temp = new Node(key); if(root == null) root = temp; else insertNode(temp); } public void insertNode(Node temp) { if(root == null) root = temp; else if(temp.getKey() <= root.getKey()) insertNode(root.getLeft()); else insertNode(root.getRight()); } Thanks for any advice.

    Read the article

  • Compilation Error on Recursive Variadic Template Function

    - by Maxpm
    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 GNU GCC with -std=C++0x. Using std=gnu++0x makes no difference.

    Read the article

  • Array: Recursive problem cracked me up

    - by VaioIsBorn
    An array of integers A[i] (i 1) is defined in the following way: an element A[k] ( k 1) is the smallest number greater than A[k-1] such that the sum of its digits is equal to the sum of the digits of the number 4* A[k-1] . You need to write a program that calculates the N th number in this array based on the given first element A[1] . INPUT: In one line of standard input there are two numbers seperated with a single space: A[1] (1 <= A[1] <= 100) and N (1 <= N <= 10000). OUTPUT: The standard output should only contain a single integer A[N] , the Nth number of the defined sequence. Input: 7 4 Output: 79 Explanation: Elements of the array are as follows: 7, 19, 49, 79... and the 4th element is solution. I tried solving this by coding a separate function that for a given number A[k] calculates the sum of it's digits and finds the smallest number greater than A[k-1] as it says in the problem, but with no success. The first testing failed because of a memory limit, the second testing failed because of a time limit, and now i don't have any possible idea how to solve this. One friend suggested recursion, but i don't know how to set that. Anyone who can help me in any way please write, also suggest some ideas about using recursion/DP for solving this problem. Thanks.

    Read the article

  • 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

  • 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 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

  • 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

  • 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

  • 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

  • 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 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

  • 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

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