Last active
February 22, 2019 07:09
-
-
Save Ben1980/29aac691f67fc48deff8e62cfbb95588 to your computer and use it in GitHub Desktop.
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
std::vector<Complex> vec = { { 3, 1}, | |
{ 1, 9 }, | |
{ 8, 2 }, | |
{ 3, 14 }}; | |
double Complex::*var; | |
auto comparator = [&var](const Complex &a, const Complex &b) { return a.*var < b.*var; }; | |
var = &Complex::real; //Sorting for real numbers | |
std::sort(vec.begin(), vec.end(), comparator); | |
var = &Complex::imaginary; //Sorting for imaginary numbers | |
std::sort(vec.begin(), vec.end(), comparator); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment