View Single Post
  #4 (permalink)  
Old 12-04-2008, 5:59 AM
cjard's Avatar
cjard cjard is offline
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Most recursive problems can actually be solved using loops which may be easier. In the case of directory searching you would use a Stack or a Queue collection.

Stack is LastIn-FirstOut like the stack of plates in a restaurant
Queue is FirstIn-FirstOut like the queue of people getting their food in the restaurant

You put one directory into the Queue to start with then start a loop that runs While Queue Length Is Greater Than Zero,
scan the current queued directory for more directories and push them into the queu, then process the files

Obviously the loop keeps running while more directories are pushed in. To work out the directory depth in this way you'd probably have to count the number of \ in the path


If you used a stack, then the search would dig down before it went across, if you use a queue it goes across before it goes down. A simple recursive search is more like a stack, you'd have to get a bit more complicated with recursion to do a breadth-first search

-

If you can say what is confusing you about recursion I can possibly explain it
__________________
DW1 DW2 DW3 DW4 DNU PQ
Reply With Quote