Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<iomanip>
- #include<fstream>
- #include<cstdlib>
- using namespace std;
- int main(int argc, char **argv){
- const char* file_name = argv[2];
- char undirected = argv[1][0];
- // open file
- fstream file(file_name, ios::in | ios::binary);
- ofstream outfile;
- outfile.open (argv[3]);
- int vertices_count = 0;
- long long edges_count = 0;
- // read header
- file.read((char*)(&vertices_count), sizeof(int));
- file.read((char*)(&edges_count), sizeof(long long));
- // print graph
- //cout << "Graph has " << vertices_count << " vertices" << endl;
- //cout << "Graph has " << edges_count << " edges" << endl;
- // get & print graph data for WEIGHTED graph
- for(long long i = 0; i < edges_count; i++)
- {
- int src_id = 0, dst_id = 0;
- float weight = 0;
- // read i-th edge data
- file.read((char*)(&src_id), sizeof(int));
- file.read((char*)(&dst_id), sizeof(int));
- file.read((char*)(&weight), sizeof(float)); // remove it for unweighed graph
- //print edge data
- outfile << src_id << " " << dst_id << endl;
- if (undirected == '1'){
- outfile << dst_id << " " << src_id << endl;
- }
- }
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement