Difference between revisions of "CPP/ParallelSort"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==ParallelSort.cpp== <source lang="cpp"> #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; void StructMethod(); struct NumberNa…') |
Daviddoria (Talk | contribs) |
||
Line 7: | Line 7: | ||
using namespace std; | using namespace std; | ||
− | |||
− | |||
struct NumberName | struct NumberName | ||
Line 22: | Line 20: | ||
int main (int argc, char *argv[]) | int main (int argc, char *argv[]) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{ | { | ||
vector<string> Names; | vector<string> Names; | ||
Line 53: | Line 44: | ||
cout << Pairs[i].index << " " << Pairs[i].Name << endl; | cout << Pairs[i].index << " " << Pairs[i].Name << endl; | ||
} | } | ||
+ | |||
+ | return 0; | ||
} | } | ||
+ | |||
</source> | </source> |
Latest revision as of 07:10, 25 June 2010
ParallelSort.cpp
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; struct NumberName { int index; string Name; }; bool operator<(NumberName NN1, NumberName NN2) { return NN1.index < NN2.index; } int main (int argc, char *argv[]) { vector<string> Names; Names.push_back("Name1"); Names.push_back("Name2"); Names.push_back("Name3"); vector<int> Ints; Ints.push_back(4); Ints.push_back(1); Ints.push_back(7); vector<NumberName> Pairs(Names.size()); for(int i = 0; i < Names.size(); i++) { Pairs[i].index = Ints[i]; Pairs[i].Name = Names[i]; } sort(Pairs.begin(), Pairs.end()); for(int i = 0; i < Pairs.size(); i++) { cout << Pairs[i].index << " " << Pairs[i].Name << endl; } return 0; }