tags:

views:

74

answers:

2

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.

+2  A: 

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.

Jackson
whether the graph has cycles may also be a concern
jk
I am trying it for undirected graph with no edge weights, I haven't tried the package ur suggested
Nilesh
Hello all, Thanx those who all are replied my first question.I have implemented BFS to reach till the target node while moving from the graph till the end node I am storing all the node (say Parent Node) and their out coming nodes (child nodes) in array of tcl. But Now I am unable to retrieve all paths between two nodes.Wating for Your answer......
Nilesh
A: 

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 }
}
Hai Vu