Advertisement
myname0

add graph

Nov 15th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. public void AddVertex(object vertex)
  2.         {
  3.             List<object> tmp = new List<object>();
  4.             graph.Add(vertex, tmp);
  5.  
  6.             Console.WriteLine("Do you want to add outcomming vertices? ");
  7.             string answer = Console.ReadLine();
  8.             if (answer == "yes")
  9.             {
  10.                 Console.WriteLine("Enter outcomming vertices: ");
  11.                 string[] outcomingVetices = Console.ReadLine().Split(' ');
  12.                 for (int i = 0; i < outcomingVetices.Length; i++)
  13.                     tmp.Add(int.Parse(outcomingVetices[i]));
  14.             }
  15.  
  16.             Console.WriteLine("Do you want to add incomming vertices? ");
  17.             answer = Console.ReadLine();
  18.             if (answer == "yes")
  19.             {
  20.                 Console.WriteLine("Enter outcomming vertices: ");
  21.                 string[] outcomingVetices = Console.ReadLine().Split(' ');
  22.                 for (int i = 0; i < outcomingVetices.Length; i++)
  23.                 {
  24.                     object vert = int.Parse(outcomingVetices[i]);
  25.                     graph[vert].Add(vertex);
  26.                 }
  27.             }
  28.         }
  29.  
  30.         public void AddEdge(object firstVertex, object secondVertex)
  31.         {
  32.             graph[firstVertex].Add(secondVertex);
  33.         }
  34.  
  35.         public void RemoveVertex(object vertex)
  36.         {
  37.             graph.Remove(vertex);
  38.             foreach (var item in graph)
  39.             {
  40.                 if (item.Value.Contains(vertex))
  41.                     item.Value.Remove(vertex);
  42.             }
  43.         }
  44.  
  45.         public void RemoveEdge(object firstVertex, object secondVertex)
  46.         {
  47.             graph[firstVertex].Remove(secondVertex);
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement