This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Performance and the fly likes Need algorithm: treewalker without recursion. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Need algorithm: treewalker without recursion." Watch "Need algorithm: treewalker without recursion." New topic
Author

Need algorithm: treewalker without recursion.

Stephane Clinckart
Ranch Hand

Joined: Oct 21, 2003
Posts: 89
Hi,

I would like to make a recursion on a tree without using the recursion pattern.

Where may I find a algorithm for that?

Thanks a lot.

Stephane Clinckart
Stephane Clinckart
Ranch Hand

Joined: Oct 21, 2003
Posts: 89
Stephane Clinckart wrote:Hi,

I would like to make a recursion on a tree without using the recursion pattern.

Where may I find a algorithm for that?

Thanks a lot.

Stephane Clinckart


I found something:

import os, os.path

startDir = "/"

directories = [startDir]
while len(directories)>0:
directory = directories.pop()
for name in os.listdir(directory):
fullpath = os.path.join(directory,name)
if os.path.isfile(fullpath):
print fullpath # That's a file. Do something with it.
elif os.path.isdir(fullpath):
directories.append(fullpath) # It's a directory, store it.

I still waiting other proposals more efficient... multithreaded by exemple.

Thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need algorithm: treewalker without recursion.
 
Similar Threads
Recursion on Android
Java Actually - Data Structure?
recursion
Can anybody solve the problem without using loop
maze program help