added doc
This commit is contained in:
parent
af4b814adb
commit
c28abc8804
2 changed files with 41 additions and 0 deletions
|
|
@ -180,6 +180,7 @@ var docs = {
|
|||
"docs/less.less": "LESS",
|
||||
"docs/html.html": "HTML",
|
||||
"docs/xml.xml": "XML",
|
||||
"docs/tcl.tcl": "Tcl",
|
||||
"docs/yaml.yaml": "YAML",
|
||||
"docs/svg.svg": "SVG",
|
||||
"docs/php.php": "PHP",
|
||||
|
|
|
|||
40
demo/kitchen-sink/docs/tcl.tcl
Normal file
40
demo/kitchen-sink/docs/tcl.tcl
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
proc dijkstra {graph origin} {
|
||||
# Initialize
|
||||
dict for {vertex distmap} $graph {
|
||||
dict set dist $vertex Inf
|
||||
dict set path $vertex {}
|
||||
}
|
||||
dict set dist $origin 0
|
||||
dict set path $origin [list $origin]
|
||||
|
||||
while {[dict size $graph]} {
|
||||
# Find unhandled node with least weight
|
||||
set d Inf
|
||||
dict for {uu -} $graph {
|
||||
if {$d > [set dd [dict get $dist $uu]]} {
|
||||
set u $uu
|
||||
set d $dd
|
||||
}
|
||||
}
|
||||
|
||||
# No such node; graph must be disconnected
|
||||
if {$d == Inf} break
|
||||
|
||||
# Update the weights for nodes\
|
||||
lead to by the node we've picked
|
||||
dict for {v dd} [dict get $graph $u] {
|
||||
if {[dict exists $graph $v]} {
|
||||
set alt [expr {$d + $dd}]
|
||||
if {$alt < [dict get $dist $v]} {
|
||||
dict set dist $v $alt
|
||||
dict set path $v [list {*}[dict get $path $u] $v]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Remove chosen node from graph still to be handled
|
||||
dict unset graph $u
|
||||
}
|
||||
return [list $dist $path]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue