Hello all,
I am trying to implement breadth-first search algorithm but I am unable to implement , and I am new user of TCL can any one help me to implement this algorithm in tcl.
Hello all,
I am trying to implement breadth-first search algorithm but I am unable to implement , and I am new user of TCL can any one help me to implement this algorithm in tcl.
I think we need a bit more detail before we can help.
So, are we are talking about a graph, if so what type? The simplest would be a undirected graph with no edge weights but is this the case?
Do you have a data structure for the graph, if so what is it?
Finally why are you re-inventing the wheel? Tcllib has the struct::graph package which implements breadth first search, see the walk command. Can you use this or the algorithms in the struct::graph::op package to do what you want.
If you are searching for files instead of generic objects, look up the command for_recursive_glob in the Tclx package. Here is a quick example:
package require Tclx
for_recursive_glob fileName {/path/to/dir1 /to/dir2} {*.txt *.doc} { puts $fileName }
The document said for_recursive_glob use breadth-first algorithm. If you want to exit prematurely (i.e. found what you were looking for), use the 'break' command to exit the for loop:
package require Tclx
for_recursive_glob fileName {/path/to/dir1 /to/dir2} {*.txt *.doc} {
puts $fileName
if {[string match *myfile*]} { break }
}