3 // author: Dan Lewis (dihlewis@yahoo.co.uk)
8 using System
.Collections
;
10 class DependencyGraph
{
11 public DependencyGraph () {
12 nodes
= new Hashtable ();
15 public void AddNode (object o
) {
16 if (!nodes
.Contains (o
))
17 nodes
.Add (o
, new Node (o
));
20 public void AddEdge (object from, object to
) {
21 if (!nodes
.Contains (from))
23 if (!nodes
.Contains (to
))
26 Node from_node
= (Node
)nodes
[from];
27 Node to_node
= (Node
)nodes
[to
];
29 from_node
.edges
.Add (to_node
);
32 public IList
TopologicalSort () {
33 foreach (Node node
in nodes
.Values
)
36 IList list
= new ArrayList ();
37 foreach (Node node
in nodes
.Values
) {
47 private void Visit (Node node
, IList list
) {
49 foreach (Node adj
in node
.edges
) {
54 list
.Insert (0, node
.value);
58 public Node (object o
) {
60 this.edges
= new ArrayList ();
64 public ArrayList edges
;
68 private Hashtable nodes
;