Created
March 11, 2022 21:40
-
-
Save JustinStitt/c05696755277413186b09ac494509227 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
#include <bits/stdc++.h> | |
using std::vector; | |
namespace compare { | |
struct OddThenEven { | |
bool operator()(int a, int b) { | |
bool ao = (a & 1), bo = (b & 1); | |
if (ao and bo) return a < b; | |
else if (ao and !bo) return 1; | |
else if (!ao and !bo) return a < b; | |
return 0; | |
} | |
}; | |
}; | |
void evenOddSort(vector<int>& v) { | |
#define all(a) a.begin(), a.end() | |
std::sort(all(v), compare::OddThenEven()); | |
} | |
int main() { | |
vector<int> test = {7,8,1,4,5,7,11,6,14,26,13}; | |
evenOddSort(test); | |
for(auto&& e : test) std::cout << e << " "; | |
std::cout << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment