469,898 Members | 2,347 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

recursive stuff

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

Nov 20 '05 #1
1 1035
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

"Dane Carty" <da**@REMOVEMEcartyonline.net> wrote in message
news:Qr*******************@front-1.news.blueyonder.co.uk...
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


Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by replace-this-with-my-name | last post: by
7 posts views Thread by Jon Slaughter | last post: by
4 posts views Thread by Nicolas Vigier | last post: by
64 posts views Thread by dmattis | last post: by
9 posts views Thread by Csaba Gabor | last post: by
14 posts views Thread by Fabian Steiner | last post: by
8 posts views Thread by joel_maina | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.