From 9fe033ea88c2f705ec18c232873d056e0c229d72 Mon Sep 17 00:00:00 2001 From: Gaspard Coulet Date: Wed, 28 Apr 2021 23:05:53 +0200 Subject: Initial commit --- sem_5/HLIN501_Graphes/TP/TP2/tribulle.cc | 189 +++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 sem_5/HLIN501_Graphes/TP/TP2/tribulle.cc (limited to 'sem_5/HLIN501_Graphes/TP/TP2/tribulle.cc') diff --git a/sem_5/HLIN501_Graphes/TP/TP2/tribulle.cc b/sem_5/HLIN501_Graphes/TP/TP2/tribulle.cc new file mode 100644 index 0000000..0266596 --- /dev/null +++ b/sem_5/HLIN501_Graphes/TP/TP2/tribulle.cc @@ -0,0 +1,189 @@ +#include +#include +#include +#include +#include + +typedef struct coord{int abs; int ord;} coord; +void pointRandom(int n, coord point[]); +void distances(int n, int m, coord point[], int edge[][3]); +void tri(int m, int edge[][3]); +void affichageGraphique(int n, int m, coord point[], int arbre[][2], const char * filename); +void kruskal (int n, int edge[][3], int arbre[][2]); +void fusion(int tableau[][3],int deb1,int fin1,int fin2); +void tri_fusion(int tableau[][3],int longueur); +void tri_fusion_bis(int tableau[][3],int deb,int fin); +using namespace std; + +int +main() +{ + int n; //Le nombre de points. + cout << "Entrer le nombre de points: "; + cin >> n; + int m=n*(n-1)/2; // Le nombre de paires de points. + coord point[n]; // Les coordonnees des points dans le plan. + int edge[m][3]; // Les paires de points et le carre de leur longueur. + int arbre[n-1][2]; // Les aretes de l'arbre de Kruskal. + pointRandom(n,point); + distances(n,m,point,edge); + tri(m,edge); + for (int i =0; i < m; i ++){ + cout << "point "<< edge[i][0]<<":"<0) + { + tri_fusion_bis(tableau,0,longueur-1); + } + } +void tri(int m, int edge[][3]){ + for (int i = 0 ; i < m ; i ++){ + for(int j=i+1; j < m; j ++){ + if ( edge[i][2]>edge[j][2]){ + swap(edge[i][0],edge[j][0]); + swap(edge[i][1],edge[j][1]); + swap(edge[i][2],edge[j][2]); + } + } + } +} + +void affichageGraphique(int n, int m, coord point[], int arbre[][2], const char * filename) +// Cree le fichier Exemple.ps qui affiche +// les points et l'arbre de Kruskal. +{ + ofstream output; + output.open(filename,ios::out); + output << "%!PS-Adobe-3.0" << endl; + output << "%%BoundingBox: 0 0 612 792" << endl; + output << endl; + for(int i=0;i