adding the iterator exercise code
This commit is contained in:
@@ -140,6 +140,36 @@ itr++;
|
||||
assert (*itr == 100); // might seem ok... but rewrite the code to avoid this!
|
||||
```
|
||||
|
||||
### Exercise
|
||||
|
||||
What is the output of this program?
|
||||
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
|
||||
```cpp
|
||||
int main(){
|
||||
|
||||
std::list<int> lst;
|
||||
lst.push_back(150);
|
||||
lst.push_back(250);
|
||||
lst.push_back(350);
|
||||
lst.push_back(450);
|
||||
|
||||
std::list<int>::iterator itr;
|
||||
itr = lst.begin();
|
||||
++itr;
|
||||
*itr += 5;
|
||||
|
||||
std::list<int>::iterator itr2 = lst.begin();
|
||||
while(itr2 != lst.end()){
|
||||
std::cout << *itr2 << std::endl;
|
||||
itr2++;
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
## 10.3 Working towards our own version of the STL list
|
||||
|
||||
- Our discussion of how the STL list<T> is implemented has been intuitive: it is a “chain” of objects.
|
||||
|
||||
Reference in New Issue
Block a user