Created
October 26, 2013 13:54
-
-
Save msulima/7169716 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
void printStringVector(vector<string*> &v) ; | |
void freeDictionary(vector<string*> &v); | |
vector<string*> loadDictionary(); | |
struct StringSorter { | |
bool operator() (string* lhs, string* rhs) { | |
return string(lhs->rbegin(), lhs->rend()) < string(rhs->rbegin(), rhs->rend()); | |
} | |
}; | |
int main() { | |
vector<string*> dictionary = loadDictionary(); | |
StringSorter stringSorter; | |
sort(dictionary.begin(), dictionary.end(), stringSorter); | |
printStringVector(dictionary); | |
freeDictionary(dictionary); | |
return 0; | |
} | |
void printStringVector(vector<string*> &v) { | |
for (vector<string*>::iterator it = v.begin(); it != v.end(); it++) { | |
cout << **it << endl; | |
} | |
} | |
void freeDictionary(vector<string*> &v) { | |
for (vector<string*>::iterator it = v.begin(); it != v.end(); it++) { | |
delete *it; | |
} | |
} | |
vector<string*> loadDictionary() { | |
vector<string*> dictionary; | |
dictionary.push_back(new string("mozna")); | |
dictionary.push_back(new string("miec")); | |
dictionary.push_back(new string("kilka")); | |
dictionary.push_back(new string("egzemplarzy")); | |
dictionary.push_back(new string("klasy")); | |
dictionary.push_back(new string("obiektu")); | |
dictionary.push_back(new string("funkcyjnego")); | |
return dictionary; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment