// Creating a graph with integer vertices var graph = new Graph(); // Adding vertices to the graph graph.AddVertex(1); graph.AddVertex(2); graph.AddVertex(3); // Adding edges between vertices graph.AddEdge(1, 2); graph.AddEdge(2, 3); // Getting the number of vertices in the graph var numVertices = graph.Vertices.Count;
// Creating a graph with string vertices var graph = new GraphIn this example, we create a graph with string vertices, add three vertices to the graph, and add edges between the vertices. We then get all the vertices adjacent to the vertex "B". Package library: Vertices Any.(); // Adding vertices to the graph graph.AddVertex("A"); graph.AddVertex("B"); graph.AddVertex("C"); // Adding edges between vertices graph.AddEdge("A", "B"); graph.AddEdge("B", "C"); // Getting all vertices adjacent to a given vertex var adjacentVertices = graph.GetAdjacentVertices("B");