federico-busato / Modern-CPP-Programming

Modern C++ Programming Course (C++03/11/14/17/20/23/26)

Home Page:https://federico-busato.github.io/Modern-CPP-Programming/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fixes in Iterators Containers

leofracca opened this issue · comments

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 use std::sort
    • arr1 and arr2 need to be of the same size, otherwise operator> won't work
    • missing ; at the end of the last line of code
  • Page 20 (std::vector):
    • vec5.fill(3) does not work, since std::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 is 2, 3, 5, but I believe it should be 2, 3, 4
  • Page 21 (std::list):
    • list5.fill(3) needs to be changed to std::fill(list5.begin(), list5.end(), 3)
    • list1.merge(arr5): I believe it should be list1.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) to std::fill(queue5.begin(), queue5.end(), 3)
  • Page 23 (std::forward_list):
    • flist5.fill(4) to std::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 says empty map (it should say multiset/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 be pqueue1.push(5); pqueue1.push(4);

I hope everything is clear and I didn't make any silly mistakes!

Thanks @leofracca! All of them are valid comments. I also took the opportunity to remove some verbose code in these examples