Example – undirected and unweighted edges

Let's try to use the previous implementation to create the undirected and unweighted graph, according to the following diagram:

As you can see, the graph contains 8 nodes and 10 edges. You can configure the example graph in the Main method in the Program class. The implementation starts with the following line of code, which initializes a new undirected graph (with false as the value of the first parameter) and an unweighted graph (with false as the value of the second parameter):

Graph<int> graph = new Graph<int>(false, false); 

Then, you add the necessary nodes, and store references to them as new ...

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.