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

Breadth First Search Example Sub
Deque Class

Private Sub BreadthFirstSearchExample()

Example of using the Deque as a Queue to perform a Breadth First Search.

Summary: This example performs a breadth first search to locate all of the directories within a specific hierarchy. This search strategy uses a queue to search all of the directories at the current level before descending deeper.
    ' Initialize Deque and add top-level directory.
    Dim dqDirs As New Deque
    dqDirs.QueueAdd "C:\Entisoft"
    ' Perform BFS Search for all sub-directories.
    Dim strDir As String
    Do While dqDirs.QueueRemove(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.QueueAdd strDir & "\" & strFile
                End If
            End If
            strFile = Dir$()
See also:
    DepthFirstSearchExample Topic

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