Returns a list of all the nodes in the graph in topological order. If the function succeeds the Acyclic property is set to True.
The user is responsible for freeing the TStrings result whether the function succeeded or not. You may pass in the TStrings to use in the OrderedNodes parameter.
A topological ordering of the nodes in a graph is a linear ordering which has the property that if node i is a predecessor of node j then node i precedes node j in the linear ordering. A topological order can be used to check if a graph is feasible (nothing is a prerequisite of itself, a cycle) and provides an order for performing each node in an Activity on Vertex (AOV) network. For example, you can use a graph to represent the classes a computer science student must take to graduate with a computer science degree. The nodes represent each class and the edges represent the prerequisites for the class, i.e., a student must take "Introduction to Programming" class before he/she can take the "Data Structures" class. The TopologicalOrder method will return one way the student can take the classes in the correct order, prerequisites first.
Note |
---|
Undirected graphs always fail as there are always loops. |
Namespace: GGraph
Delphi |
public |
Parameters
OrderedNodes
Type: TStrings
Type: TStrings
The following example gets a topological ordering for the graph and checks if it is successful by checking the Acyclic property: Delphi |
var |