Warum meckert Code::Blocks "undefined reference"?
-
@Swordfish Sorry, meinte ich natürlich!
-
Selbst wenn ich krampfhaft auf die Standard Library verzichte komm' ich da nicht auf ~300 Zeilen:
#include <iostream> #include <vector> #include <string> template<typename T> void insert_sorted(T &collection, typename T::value_type item) { auto it{ std::begin(collection) }; for (; it != std::end(collection) && item > *it; ++it); collection.insert(it, item); } int main() { std::vector<std::string> foo{ "a", "c", "d", "f", "h" }; insert_sorted(foo, "g"); insert_sorted(foo, "b"); insert_sorted(foo, "e"); for (auto const &f : foo) std::cout << f << '\n'; }