Skip to content

Instantly share code, notes, and snippets.

@alican
Last active May 23, 2016 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alican/0f30762909d589919c948cb95d6c7b7e to your computer and use it in GitHub Desktop.
Save alican/0f30762909d589919c948cb95d6c7b7e to your computer and use it in GitHub Desktop.
Crossover einer doppelt verketten Liste (std::list) in c++.
std::ostream& operator<<(std::ostream& ostr, const std::list<std::string>& list) {
for (auto &i : list) {
ostr << " " << i;
}
return ostr;
}
////////
int position = 4;
std::list<std::string> list1 = {"A", "B", "C", "D", "E", "F"};
std::list<std::string> list2 = {"U", "V", "W", "X", "Y", "Z"};
auto it1 = list1.begin();
std::advance(it1, position);
auto it2 = list2.begin();
std::advance(it2, position);
list1.splice(it1, list2, it2, list2.end());
list2.splice(list2.end(), list1, it1, list1.end());
std::cout << "list1: " << list1 << "\n";
std::cout << "list2: " << list2 << "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment