Initializes all the nodes in the graph. It sets each node's Visited property to the Value parameter. If the node is a TWeightedNode descendant, it also sets their Weight property to MaxInt and clears the ShortestPath property (and adds StartNode as an item).
Namespace: GGraph
Delphi
|
public
procedure InitializeNodes( StartNode: TGGraphNode; Value: Boolean ); virtual;
|
Parameters
StartNode
Type: TGGraphNode
Value
Type: Boolean
The following code prints out all the nodes reachable from node 1:
Delphi
|
begin
// call InitializeNodes and DepthFirstSearch. Alternatively, just call TraverseFrom
Graph.InitializeNodes;
Graph.DepthFirstSearch( Node1 );
// Graph.TraverseFrom( Node1 );
with Graph.GetNodes do
while HasMoreElements do
with TGGraphNode(NextElement) do
if Visited then
ListBox1.Items.Add( 'node ' + Caption + ' is reachable' )
else
ListBox1.Items.Add( 'node ' + Caption + ' is not reachable' );
end;
|