private void Add(string x, string y, int weight, bool directed)
        {
            EdgeNode oldEdgeNode;

            edges.TryGetValue(x, out oldEdgeNode);
            EdgeNode newEdgeNode = new EdgeNode(y, weight, oldEdgeNode);

            edges[x] = newEdgeNode;
            if (oldEdgeNode != null)
            {
                degrees[x] = degrees[x] + 1;
            }
            else
            {
                degrees.Add(x, 1);
            }
            if (directed == false)
            {
                Add(y, x, weight, directed: true);
            }
            else
            {
                edgeCount++;
            }
        }
 public void PrintGraph()
 {
     foreach (var pair in edges)
     {
         Console.WriteLine("{0}", pair.Key);
         EdgeNode edgeNode = pair.Value;
         while (edgeNode != null)
         {
             Console.WriteLine(" {0}-{1}", edgeNode.Weight, edgeNode.Target);
             edgeNode = edgeNode.Next;
         }
         Console.WriteLine();
     }
 }
Beispiel #3
0
 public EdgeNode(string target, int weight, EdgeNode next)
 {
     Target = target;
     Weight = weight;
     Next   = next;
 }