Fixes in Iterators Containers
leofracca opened this issue · comments
Leonardo Fraccaroli commented
Hi Federico, I think there are some errors in the Iterators Containers slides.
- Page 19 (
std::array
):#include <algorithm>
is missing; without it we cannot usestd::sort
arr1
andarr2
need to be of the same size, otherwiseoperator>
won't work- missing
;
at the end of the last line of code
- Page 20 (
std::vector
):vec5.fill(3)
does not work, sincestd::vector
does not have such a method. Instead,std::fill(vec5.begin(), vec5.end(), 3)
can be used- when it prints the elements in
vec1
, the comment is2, 3, 5
, but I believe it should be2, 3, 4
- Page 21 (
std::list
):list5.fill(3)
needs to be changed tostd::fill(list5.begin(), list5.end(), 3)
list1.merge(arr5)
: I believe it should belist1.merge(list5)
merge()
does not work as expected, since both lists should be sorted. Moreover, I think the comments after that are not correct, as they use the result of the merge as a starting point (for example I got[2, 3, 2, 3, 3, 5]
instead of[2, 3, 2, 5, 3, 3]
)
- Page 22 (
std::deque
):queue5.fill(3)
tostd::fill(queue5.begin(), queue5.end(), 3)
- Page 23 (
std::forward_list
):flist5.fill(4)
tostd::fill(flist5.begin(), flist5.end(), 4)
flist1.erase_after(flist1.begin(), 0)
does not compile- when
merge()
is called, both list should be sorted
- Page 30 (
std::multiset
):#include <multiset>
should be changed to#include <set>
- when declaring
mset2
the comment saysempty map
(it should saymultiset
/set
) *(it + 1)
does not compile (maybe*(++it)
can be used?)- during my tests that line prints 6 and 5, not 5 and 5 as the comment indicates, but I don't understand why. Maybe I am missing something
- Page 33 (
std::priority_queue
):- the last block of code does
queue1.push(5); queue1.push(4);
; but probably it should bepqueue1.push(5); pqueue1.push(4);
- the last block of code does
I hope everything is clear and I didn't make any silly mistakes!
Federico commented
Thanks @leofracca! All of them are valid comments. I also took the opportunity to remove some verbose code in these examples