Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1.  
  2. #include"pch.h"
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <vector>
  7. #include <stack>
  8. #include <sstream>
  9. #include <list>
  10. using namespace std;
  11. int edgeCount;
  12. int vCount;
  13. vector<pair<int, double>>adj[1000];
  14.  
  15.  
  16. void addEdge(vector<pair<int, double>> adj[], int u, int v, double wt)
  17. {
  18. adj[u].push_back(make_pair(v, wt));
  19. adj[v].push_back(make_pair(u, wt));
  20. }
  21.  
  22. void printGraph(vector<pair<int, double> > adj[], int V)
  23. {
  24. int v;
  25. double w;
  26. for (int u = 1; u <= V; u++)
  27. {
  28. cout << "Node " << u << " makes an edge with \n";
  29. for (auto it = adj[u].begin(); it != adj[u].end(); it++)
  30. {
  31. v = it->first;
  32. w = it->second;
  33. cout << "\tNode " << v << " with edge weight ="
  34. << w << "\n";
  35. }
  36. cout << "\n";
  37. }
  38. }
  39.  
  40. void getPath(vector<pair<int, double>> adj[], int start, int end)
  41. {
  42.  
  43. }
  44. int main()
  45. {
  46. int to;
  47. double weight;
  48. string line;
  49. string filename = "input81.txt";
  50. //getting the total edge count
  51. ifstream read(filename);
  52. if (!read.is_open())
  53. {
  54. cout << "the file is not open" << endl;
  55. }
  56. else
  57. {
  58. while (!read.eof())
  59. {
  60. getline(read, line);
  61. edgeCount++;
  62. }
  63.  
  64. cout << edgeCount << endl;
  65. read.close();
  66. }
  67.  
  68.  
  69.  
  70. //getting the actual input
  71. ifstream input(filename);
  72. if (!input.is_open())
  73. {
  74. cout << "the file is not open" << endl;
  75. }
  76. else {
  77. while (!input.eof())
  78. {
  79. getline(input, line);
  80. cout << line << endl;
  81. if (stringstream(line) >> vCount >> to >> weight)
  82. {
  83.  
  84. cout << "from " << vCount << " to " << to << " weight:" << weight << endl;
  85. addEdge(adj, vCount, to, weight);
  86. }
  87. }
  88. cout << edgeCount << endl;
  89. cout << vCount << endl;
  90.  
  91. input.close();//finish getting input
  92. }
  93.  
  94.  
  95. printGraph(adj, vCount);
  96. string path = "path81.txt";
  97. ifstream getpath(path);
  98. int src;
  99. int end;
  100. if (!getpath.is_open())
  101. cout << "the file is not open" << endl;
  102. else {
  103. while (!getpath.eof())
  104. {
  105. getpath >> src >> end;
  106. cout << src << endl << end;
  107. }
  108. }
  109. return 0;
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement