SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static void Main(string[] args)
  2. {
  3.     DAG<string> dag = new DAG<string>();
  4.     Vertex<string> vertex1 = new Vertex<string>("1");
  5.     Vertex<string> vertex2 = new Vertex<string>("2");
  6.     Vertex<string> vertex3 = new Vertex<string>("3");
  7.     Vertex<string> vertex4 = new Vertex<string>("4");
  8.     Vertex<string> vertex5 = new Vertex<string>("5");
  9.  
  10.     dag.AddVertex(vertex1);
  11.     dag.AddVertex(vertex2);
  12.     dag.AddVertex(vertex3);
  13.     dag.AddVertex(vertex4);
  14.     dag.AddVertex(vertex5);
  15.  
  16.     dag.TryAddEdge(vertex1, vertex3);
  17.     dag.TryAddEdge(vertex2, vertex3);
  18.     dag.TryAddEdge(vertex4, vertex5);
  19.     dag.TryAddEdge(vertex3, vertex5);
  20.  
  21.     var result = dag.TopologicalSort();
  22.     foreach (var item in result)
  23.     {
  24.         System.Console.WriteLine(item.Data);
  25.     }
  26.     // 1 2 4 3 5
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top