using QuickGraph; // Create a directed graph with integer vertices var graph = new AdjacencyGraph>(); // Add two vertices to the graph IVertex v1 = graph.AddVertex(1); IVertex v2 = graph.AddVertex(2); // Create an edge between the two vertices graph.AddEdge(new Edge (v1, v2));
using GraphSharp.Controls; // Create an undirected graph with string vertices var graph = new GraphLayoutIn Example 1, we use the QuickGraph package library to create a directed graph with integer vertices. We add two vertices to the graph, create an edge between them, and store the vertices as IVertex objects. In Example 2, we use the GraphSharp.Controls package library to create an undirected graph with string vertices. We add three vertices to the graph, create edges between them, and calculate the degree of vertex v1 using the Degree() method provided by the library.>(); // Add three vertices to the graph IVertex v1 = graph.AddVertex("A"); IVertex v2 = graph.AddVertex("B"); IVertex v3 = graph.AddVertex("C"); // Create edges between the vertices graph.AddEdge(new UndirectedEdge (v1, v2)); graph.AddEdge(new UndirectedEdge (v2, v3)); graph.AddEdge(new UndirectedEdge (v3, v1)); // Calculate the degree of vertex v1 int degree = graph.Degree(v1);