Last active
May 23, 2016 20:06
-
-
Save alican/0f30762909d589919c948cb95d6c7b7e to your computer and use it in GitHub Desktop.
Crossover einer doppelt verketten Liste (std::list) in c++.
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::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