-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (47 loc) · 1.92 KB
/
Copy pathProgram.cs
File metadata and controls
54 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using PSI_Project_Perso;
namespace PSI_Project_Perso
{
class Program
{
static void Main()
{
// obtenir les donnees de graphe et creation deu graphe
List<(int, int)> edges = ReadEdgesFromFile("soc-karate.mtx");
Graphe graph = new Graphe(edges);
Console.WriteLine("\nOrdre de graphe (le nombre de sommets qu'il contient) = " + graph.OrdreDeGraphe());
Console.WriteLine("\nTaille de graphe (le nombre d'arêtes du graphe) = " + graph.TailleDeGraphe());
// imprimer la matrice d'adjacence
graph.AfficherMatrice();
Console.WriteLine("\nGraph est non-orienté ? " + (graph.EstNonOriente() ? "Oui" : "Non"));
// executer le DFS et avoir le resultat
Console.WriteLine("\nExécution de DFS:");
graph.DFS_Main();
Console.WriteLine(graph.ContientCycle ? "Le graphe contient un cycle." : "Le graphe ne contient pas de cycle.");
// executer le BFS, obtenir l'ordre de visite
Console.WriteLine("\nExécution de BFS depuis le sommet 1:");
List<int> bfsOrder = graph.BFS(1);
graph.AfficherBFSOrder(bfsOrder);
}
/// <summary>
/// obtenir les donnees de graphe et obtenir le liste des arcs
/// </summary>
static List<(int, int)> ReadEdgesFromFile(string filePath)
{
List<(int, int)> edges = new List<(int, int)>();
using (StreamReader sr = new StreamReader(filePath))
{
string data;
while ((data = sr.ReadLine()) != null)
{
int[] numbers = data.Split(' ').Select(int.Parse).ToArray();
edges.Add((numbers[0], numbers[1]));
}
}
return edges;
}
}
}