Advertisement
Guest User

Untitled

a guest
May 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. int vertex::count = 0;
  2.  
  3. vertex::vertex(point coordinates)
  4. {
  5. id = vertex::count;
  6. vertex::count++;
  7. coords = coordinates;
  8. }
  9.  
  10. vertex::vertex(string vertexname)
  11. {
  12. id = vertex::count;
  13. vertex::count++;
  14. name = vertexname;
  15. }
  16.  
  17. void vertex::addNeighbour(vertex* neigh)
  18. {
  19. neighbours.push_back(neigh);
  20. }
  21.  
  22.  
  23. string vertex::toString()
  24. {
  25. string str=getName();
  26. cout << "Printing vertex: " << str << endl;
  27. str.append(" at (");
  28. str.append(doubleToString(coords.x()));
  29. str.append("|");
  30. str.append(doubleToString(coords.y()));
  31. str.append("), has ");
  32.  
  33. stringstream tmp;
  34. tmp << neighbours.size();
  35. str.append(tmp.str());
  36.  
  37. str.append(" neighbours: |");
  38.  
  39. for (vector <vertex*>::iterator it = neighbours.begin(); it != neighbours.end(); ++it)
  40. {
  41. cout << "Found neighbour "<< (*it)->getName() << endl; //this segfaults
  42. str.append((*it)->getName());
  43. str.append("|");
  44. }
  45.  
  46. return str;
  47. }
  48.  
  49. string vertex::getName()
  50. {
  51. return name;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement