Академический Документы
Профессиональный Документы
Культура Документы
cpp
* Abstract: Implements the Prim’s algorithm to calculate the minimum spanning tree (MST) from an input graph
* Author: Sergiy Zarubin
* ID: 1337
* Date: 06/16/2019
*/
#include <iostream>
#include <fstream>
struct graphMST {
int source;
int dist;
int cost;
};
}
void printMatrix (int** matrix,int size){
int main(){
/*Declaring variables*/
string fileName;
string line;
/*Get filename*/
cout << "Please enter file name: ";
getline(cin, fileName);
for(int i=0;i<no_nodes;i++){
selected[i] = false;
}
getline(sampleFile, line);
int no_edges = stoi(line);
//cout<<"Creating Matrix"<<endl;
int **matrix = new int* [no_edges];
if (sampleFile.is_open()){
for (int row = 0; row < no_edges; row++){
sampleFile>> newGraph[row].source;
sampleFile>> newGraph[row].dist;
sampleFile>> newGraph[row].cost;
//ofset location by one
//and make it undirected
matrix[newGraph[row].source-1][newGraph[row].dist-1] = newGraph[row].cost;
matrix[newGraph[row].dist-1][newGraph[row].source-1] = newGraph[row].cost;
getline(sampleFile, line);
}
sampleFile.close();
}
//printGraph(newGraph,no_edges) ;
//printMatrix(matrix,no_edges);
int mst_edge = 0;
int first;
while (mst_edge<no_nodes-1){
int min = INF;
int x=0; int y=0;
}
}
}
}
}
mst_edge++;
cout<<"("<<mst_edge<<") New edge: "<<x+1<<","<<y+1<<" – cost "<<matrix[x][y]<<endl;
selected[y] = true;
delete[] newGraph;
return 0;
}catch(exception const& e){
cout << "There was an error: " << e.what() << endl;
}
return 0;
}