recursive stuff

  • Thread starter Thread starter Dane Carty
  • Start date Start date
D

Dane Carty

Hi,

Using a TreeView component to create a tree of the directories within my
file system.

I can't get my head around the logic of the recursion. Anyone with a bigger
brain is welcome to help!!

I want the vaild drives to be the top layer with 'children' drilling down
through the directory structure.

Many thanks in advance
Dane
 
Hi, Dane

I suggest to take any basic CS book and check there examples for n!
calculation - which is classic example of recursive solution of the problem.
Basically it means, that your definition of recursive function should call
itself with arguments, which allow to reduce complexity of solved task

for example:

int Factorial(int n) {
if (n<0) throw new Exception("I don't know how to calculate factorial for
negative number!");
if (n=0) return 0;
return n*Factorial(n-1);
}

Try to run this in debugger, say as Factorial(4), and see step by step what
happens. Just don't call it with too big N, you might get overflow or stack
exception.

Same logic would apply to traversing trees like directory structure

HTH
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top