Table of Contents

Class GraphWithAdjacentsSet

Namespace
AlgorithmsSW.Graph
Assembly
AlgorithmsSW.dll
[ExerciseReference(4, 1, 5)]
public class GraphWithAdjacentsSet : IGraph, IReadOnlyGraph, IEnumerable<(int vertex0, int vertex1)>, IEnumerable
Inheritance
GraphWithAdjacentsSet
Implements
Inherited Members
Extension Methods

Constructors

GraphWithAdjacentsSet(GraphWithAdjacentsSet)

[ExerciseReference(4, 1, 3)]
public GraphWithAdjacentsSet(GraphWithAdjacentsSet graph)

Parameters

graph GraphWithAdjacentsSet

GraphWithAdjacentsSet(int)

public GraphWithAdjacentsSet(int vertexCount)

Parameters

vertexCount int

GraphWithAdjacentsSet(int, Func<ISet<int>>)

public GraphWithAdjacentsSet(int vertexCount, Func<ISet<int>> setFactory)

Parameters

vertexCount int
setFactory Func<ISet<int>>

Properties

EdgeCount

Gets the number of edges in the graph.

public int EdgeCount { get; }

Property Value

int

VertexCount

Gets the number of vertices in the graph.

public int VertexCount { get; }

Property Value

int

Methods

AddEdge(int, int)

Adds an edge between two vertices in the graph.

public void AddEdge(int vertex0, int vertex1)

Parameters

vertex0 int

The first vertex of the edge to add.

vertex1 int

The second vertex of the edge to add.

Remarks

Does not support parallel edges.

Exceptions

ArgumentException

the edge you are trying to add is parallel to an existing edge.

ContainsEdge(int, int)

Gets whether the graph contains an edge between two vertices.

public bool ContainsEdge(int vertex0, int vertex1)

Parameters

vertex0 int
vertex1 int

Returns

bool

GetAdjacents(int)

Gets the adjacent vertices of a given vertex.

public IEnumerable<int> GetAdjacents(int vertex)

Parameters

vertex int

The vertex to find adjacents for.

Returns

IEnumerable<int>

An enumerable of adjacent vertices.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<(int vertex0, int vertex1)> GetEnumerator()

Returns

IEnumerator<(int vertex0, int vertex1)>

An enumerator that can be used to iterate through the collection.

RemoveEdge(int, int)

Removes an edge between two vertices in the graph.

public bool RemoveEdge(int vertex0, int vertex1)

Parameters

vertex0 int

The first vertex of the edge to remove.

vertex1 int

The second vertex of the edge to remove.

Returns

bool

true if the edge was removed, false otherwise.