Skip to content

Instantly share code, notes, and snippets.

@Trass3r

Trass3r/algorithms.h

Created Jul 10, 2020
Embed
What would you like to do?
useful algorithms
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
You can’t perform that action at this time.