|
What do you mean by "generic collection" ("אוסף גנרי")? |
I suggest you solve the dry part once you learn about iterators and generic collections in class. Anyway, if you wish to start earlier, here's a brief explanation. A "generic collection" is represented by two iterators: one points to the beginning of the collection, and another to its end. The second (end) iterator does not point to an element inside the collection, but one position further (similarly to std::vector::end()). You can assume that both iterators refer to the same collection, meaning if we advance the first iterator over and over again, we will eventually reach the second iterator. You can also assume that the iterators provide all functionality provided by the STL iterators. As an example, the implementation of a function that receives as an argument a generic collection, and returns its size, would look like this:
template <class Iterator> int getSize(Iterator begin, Iterator end) { int size = 0; for (Iterator i = begin; i != end; ++i) { ++size; } return size; }
|
|