Esempio n. 1
0
        public void AddEdge(int vertex, int weight)
        {
            if (AdjList.ContainsKey(vertex))
            {
                AdjList[vertex].Add(weight);
            }
            else
            {
                var list = new List <int>
                {
                    weight
                };
                AdjList.Add(vertex, list);
            }

            if (AdjList.ContainsKey(weight))
            {
                AdjList[weight].Add(vertex);
            }
            else
            {
                var list = new List <int>
                {
                    vertex
                };
                AdjList.Add(weight, list);
            }
        }
 public void AddEdge(NodeD start, NodeD end, int weight)
 {
     if (AdjList.ContainsKey(start) && AdjList.ContainsKey(end))
     {
         LinkedList <DEdge> neighbor = new LinkedList <DEdge>();
         AdjList.TryGetValue(start, out neighbor);
         DEdge edge = new DEdge(start, end, weight);
         neighbor.AddFirst(edge);
         AdjList[start] = neighbor;
     }
     else
     {
         throw null;
     }
 }