Created
July 10, 2020 09:11
-
-
Save Trass3r/93ece025888135710a267ee10afb696c to your computer and use it in GitHub Desktop.
useful algorithms
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
template <typename Container> | |
static void moveElementToFront(Container& c, const typename Container::value_type& e) | |
{ | |
auto it = std::find(c.begin(), c.end(), e); | |
if (it != c.end()) | |
std::rotate(c.begin(), it, it + 1); | |
} | |
// TODO: multi-element version and non-contiguous version using std::partition | |
template <typename Container> | |
static void moveElementToBack(Container& c, const typename Container::value_type& e) | |
{ | |
auto it = std::find(c.begin(), c.end(), e); | |
if (it != c.end()) | |
std::rotate(it, it + 1, c.end()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment