<-- Previous || Up || Next -->

Depth First Search Example Sub
Deque Class

Private Sub DepthFirstSearchExample()

Example of using the Deque as a Stack to perform a Depth First Search.

Summary: This example performs a depth first search to locate all of the directories within a specific hierarchy. This search strategy uses a stack to descend as far down as it can before completing the search of the current level.
    ' Initialize Deque and add top-level directory.
    Dim dqDirs As New Deque
    dqDirs.StackPush "C:\Entisoft"
    ' Perform DFS Search for all sub-directories.
    Dim strDir As String
    Do While dqDirs.StackPop(strDir)
        Debug.Print strDir
        ' Get list of all sub-directories within current directory.
        Dim strFile As String
        strFile = Dir$(strDir & "\*.*", vbDirectory)
        Do Until strFile = ""
            If strFile <> "." And strFile <> ".." Then
                If GetAttr(strDir & "\" & strFile) And vbDirectory Then
                    dqDirs.StackPush strDir & "\" & strFile
                End If
            End If
            strFile = Dir$()
See also:
    BreadthFirstSearchExample Topic

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.