#include "vertexlist.h" int vertexlist::findVertex(const vertex v) const { for (int i=0; i<(int)vl.size(); i++) { if (vl[i] == v) return i; } return -1; } int vertexlist::findVertex(const string s) const { for (int i=0; i<(int)vl.size(); i++) { if (vl[i].name == s) return i; } return -1; } int vertexlist::findVertex(const char* s) const { for (int i=0; i<(int)vl.size(); i++) { if (vl[i].name == s) return i; } return -1; } int vertexlist::addVertex(const vertex v, vector >& adjList, vector >& adjMatrix) { int i; if (findVertex(v) != -1) return -1; for (i=0; i<(int)vl.size(); i++) { adjMatrix[i].push_back(0.0); } vl.push_back(v); vector x; adjList.push_back(x); vector y; adjMatrix.push_back(y); for (i=0; i<(int)vl.size(); i++) { adjMatrix[adjMatrix.size()-1].push_back(0.0); } return vl.size()-1; } int vertexlist::addVertex(const string s, vector >& adjList, vector >& adjMatrix) { vertex v(s); return addVertex(v, adjList, adjMatrix); } int vertexlist::addVertex(const char* s, vector >& adjList, vector >& adjMatrix) { vertex v(s); return addVertex(v, adjList, adjMatrix); } unsigned int vertexlist::size() const { return vl.size(); } const string vertexlist::getVertexName(const int ndx) const { if (ndx < (int)vl.size() && ndx >= 0) return vl[ndx].name; else throw "Error: Unknown vertex"; } ostream& operator<<(ostream& strm, const vertexlist& vl) { for (int i=0; i<(int)vl.vl.size(); i++) { if (i > 0) strm << ", "; strm << vl.vl[i]; } return strm; }