Created
October 1, 2013 21:19
-
-
Save goyalankit/6785255 to your computer and use it in GitHub Desktop.
Sorts the two column file based on the second column.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
#include<fstream> | |
#include<cmath> | |
#include<cstdlib> | |
#include <algorithm> | |
using namespace std; | |
struct sort_pred { | |
bool operator()(const std::pair<int,double> &left, const std::pair<int,double> &right) { | |
return left.second > right.second; | |
} | |
}; | |
int main(int argc, char** argv ){ | |
if(argc < 3){ | |
cout << "Usage: ./a.out <filename(string)> <vertex-count(int)>" << endl; | |
exit(0); | |
} | |
vector< pair<int, double> > page_rank; | |
char *filename = argv[1]; | |
int node; | |
double weight; | |
cout << "reading file and trying to find number of vertices" << endl; | |
ifstream read(filename); | |
while(read >> node >> weight){ | |
page_rank.push_back( std::make_pair( node, weight )); | |
} | |
std::sort(page_rank.begin(), page_rank.end(), sort_pred()); | |
for(int i = 0; i < page_rank.size(); i++){ | |
cout << page_rank[i].first << " " << page_rank[i].second << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment