go to start Sol W5
|home |print view |recent changes |changed October 20, 2018 |
|You are <- set your identity!

Sections: Word List V2 |

Here come your solutions!

When posting code you can leave out scaffolding like the generated code from unit tests or the #includes required. If there is already a solution that is different from yours, just add yours or discuss the difference. Caution: parallel edits might cause data loss (however, versioning happens and you can retrieve an overwritten edit).

Word List V2 ^

here comes the code ...

void wlist2(std::istream& in, std::ostream& out) {
	Word w{};
	std::vector<Word> words{};

	//Out word class will take care of the correct reading.
	//It will separate words accordingly.
	std::istream_iterator<Word> inIt{in};
	std::istream_iterator<Word> inEof{};
	std::copy(inIt, inEof, std::back_inserter(words));

	//Erase equal words is significantly easier now too, because the class' operator== respects the lower case rule.
	//Thus we don't even need a predicte for std::unique
	auto last = std::unique(words.begin(), words.end());
	words.erase(last, words.end());

	//An empty word can no longer exists - nothing to do in this matter

	//Because our class implements operator < accordingly, std::sort doesn't need a predicate too
	std::sort(words.begin(), words.end());

	//Output wie gehabt
	std::ostream_iterator<Word> outIt{out, ", "};
	std::copy(words.begin(), words.end(), outIt);


|home |print view |recent changes |changed October 20, 2018 |
|You are <- set your identity!

Sol W5
go to start