using System.Collections.Generic;
using System.Threading.Tasks;
public GraphMatrix(int[,] Vertices)
this.vertices = Vertices;
public void AddEdge(int i, int y, int weight)
public void AddEdge(int i, int y)
public void RemoveEdge(int i, int y)
public bool HasEdge(int i, int y)
return vertices[i, y] != 0;
public IList<int> Succesors(int i)
IList<int> succesors = new List<int>();
for (int j = 0; j < vertices.GetLength(1); j++)
public void PrintBFS(int startV)
if (startV >= vertices.GetLength(0))
throw new ArgumentException("start node is wrong");
List<int> visited = new List<int>();
Queue<int> queue = new Queue<int>();
int current = queue.Dequeue();
Console.WriteLine(current);
foreach (int n in this.Succesors(current))
if (!visited.Contains(n))
public void PrintDFS(int startV)
if (startV >= vertices.GetLength(0))
throw new ArgumentException("start node is wrong");
List<int> visite = new List<int>();
Stack<int> stack = new Stack<int>();
int current = stack.Pop();
Console.WriteLine(current);
foreach (int n in this.Succesors(current))
static void Main(string[] args)
Console.Write("Enter node to start: ");
int start = int.Parse(Console.ReadLine());
int[,] graph = new int[,] { { 0, 1, 1, 1, 1 },
GraphMatrix gm = new GraphMatrix(graph);
Console.Write($"BFS from node {start}: ");
Console.Write($"DFS drom node {start}: ");
catch (ArgumentException e)
Console.WriteLine(e.Message);