At 10:58 AM -0700 2/2/06, Chuck Pelto wrote:
Most recurive algorithms I've seen are arbitrary in their number of
recursive levels.
I've rarely seen one like that -- the only one I can think of is a
game search function, where you want to limit the depth so it doesn't
sit there thinking forever. Most recursive algorithms continue
recursing until their work is done.
Where is an example of one that is open-ended?
Pretty much anywhere, but here, I'll make one up: it searches the
contents of a folder, recursively, until it finds the file "foo.bar":
Function FindFoo(dir as FolderItem) As FolderItem
for i as Integer = dir.Count DownTo 1
Dim f As FolderItem = dir.TrueItem( i )
if f.Name = "foo.bar" then return f // found it!
if f.Directory then
f = FindFoo(f) // (here's the recursion)
if f <> nil then return f // (here we back out once we have an answer)
end if
next
End Function
I'm just typing this into email, so it may contain a typo or two, but
that's the basic idea.
HTH,
- Joe
--
Joseph J. Strout
[EMAIL PROTECTED]
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>