You should now be familiar with the implementation of list.
Now we would like you to make your implementation conform to our standards, and that includes supporting iterators.
If you are not familiar with iterators, you might want to have a look at this introductory post.
Please read the .h source file and complete the definitions. You need to define the following functions:
iterator_impl_base &operator++(); // increments the iterator; the iterator should then point to the next node
bool operator!=(const iterator_impl_base &) const; // compares whether two iterators point to the same node
list();
~list();
void clear(); // make this list empty as if it's new
size_type size() const; // returns the number of elements in the list
bool empty() const; // returns whether the list is empty
iterator begin(); // returns an iterator that points to the first node (if none, point to end)
iterator end(); // returns an iterator that points to a special node that is the node after the last element
void insert(iterator pos, size_type count, const value_type val); // inserts #count val right before pos
void erase(iterator l, iterator r); // erase nodes with index in [l, r)
Some tips:
1. In case you need to find the address of Node when you only have the address of a member in Node: post.
2. Stuck with compling issues regarding polymorphism?: post.
3. Don't be scared. The solution by the author has less than 40 lines.
T
N_1
Q_1
Q_2
...
Q_N_1
N_2
...
N_T
...
Q is one of the two types:
"1 X C V"
"2 L R"
Where the former means you'll do insert(X, C, V), and the latter would need you to do erase(L, R).
1 <= T <= 500
1 <= N <= 1000
0 <= C <= 5
0 <= V <= 1000
0 <= L <= R <= The size of the list at the moment
0 <= X <= The size of the list at the moment
For each test case (enumerated from 1 to T), print the size of the list in one line, followed by the elements of the list.
Particularly, ignore the test case if the resulting list is empty.