// File: graph.cpp // Solutions to HW6 Fall 2003 CS 112 B by Leo Reyzin #include"graph.h" #include const int Graph::infinity = numeric_limits::max(); Graph::Graph() { weights=NULL; numVertices=0; } Graph::~Graph() { int i; if (weights!=NULL) { for (i=0; iweights[j][addedNode]) { bestEdgeWeight[j]=weights[j][addedNode]; bestDestination[j]=addedNode; // cout<<" " << j; } } // cout<<"\nBest edges: "; // Find the minimum-weight edge from uncovered to covered part minWeight=infinity; for (j=1; j=numVertices || end<0 || end>=numVertices) return INVALID_EDGE; weights[begin][end]=weights[end][begin]=weight; return SUCCESS; } ostream & operator<<(ostream & output, const Graph & graph) { int i, j; output << graph.numVertices << endl; for (i=0; i>(istream & input, Graph & graph) { int i, j, w; input >> i; if (graph.Init(i)) { do { input >> i; input >> j; input >> w; } while (graph.AddEdge(i, j, w)==Graph::SUCCESS); } return input; }