Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"pch.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <stack>
- #include <sstream>
- #include <list>
- using namespace std;
- int edgeCount;
- int vCount;
- vector<pair<int, double>>adj[1000];
- void addEdge(vector<pair<int, double>> adj[], int u, int v, double wt)
- {
- adj[u].push_back(make_pair(v, wt));
- adj[v].push_back(make_pair(u, wt));
- }
- void printGraph(vector<pair<int, double> > adj[], int V)
- {
- int v;
- double w;
- for (int u = 1; u <= V; u++)
- {
- cout << "Node " << u << " makes an edge with \n";
- for (auto it = adj[u].begin(); it != adj[u].end(); it++)
- {
- v = it->first;
- w = it->second;
- cout << "\tNode " << v << " with edge weight ="
- << w << "\n";
- }
- cout << "\n";
- }
- }
- void getPath(vector<pair<int, double>> adj[], int start, int end)
- {
- }
- int main()
- {
- int to;
- double weight;
- string line;
- string filename = "input81.txt";
- //getting the total edge count
- ifstream read(filename);
- if (!read.is_open())
- {
- cout << "the file is not open" << endl;
- }
- else
- {
- while (!read.eof())
- {
- getline(read, line);
- edgeCount++;
- }
- cout << edgeCount << endl;
- read.close();
- }
- //getting the actual input
- ifstream input(filename);
- if (!input.is_open())
- {
- cout << "the file is not open" << endl;
- }
- else {
- while (!input.eof())
- {
- getline(input, line);
- cout << line << endl;
- if (stringstream(line) >> vCount >> to >> weight)
- {
- cout << "from " << vCount << " to " << to << " weight:" << weight << endl;
- addEdge(adj, vCount, to, weight);
- }
- }
- cout << edgeCount << endl;
- cout << vCount << endl;
- input.close();//finish getting input
- }
- printGraph(adj, vCount);
- string path = "path81.txt";
- ifstream getpath(path);
- int src;
- int end;
- if (!getpath.is_open())
- cout << "the file is not open" << endl;
- else {
- while (!getpath.eof())
- {
- getpath >> src >> end;
- cout << src << endl << end;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement