From 3df95679b50fb7e17c5501f2c4801a2dc180c0f1 Mon Sep 17 00:00:00 2001 From: Patrick Diehl Date: Wed, 11 Sep 2024 21:11:58 -0600 Subject: [PATCH] Fix Listing 3.3 --- _posts/2024-08-15-addendum.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/_posts/2024-08-15-addendum.markdown b/_posts/2024-08-15-addendum.markdown index 1fed08a..9409315 100644 --- a/_posts/2024-08-15-addendum.markdown +++ b/_posts/2024-08-15-addendum.markdown @@ -8,6 +8,19 @@ tags: Addendum It does not matter how often one proofreads the book, there will be always bugs in the code or some issues. We will document the issues here and update the code on [GitHub](https://github.com/ModernCPPBook/Examples). Of course, we will update the potential new release of the book accordingly. +## Chapter 3 + +[Listing 3.3](https://github.com/ModernCPPBook/Examples/blob/main/notebooks/Chapter_3.ipynb) the cases for even and odd are wrong in the code and should be chnaged to + +{% highlight c++ %} +if (values.size() % 2 == 0) { + median = *mid; |\label{container:median:list:defref}| +} else { + auto mid_one = values.begin(); + std::advance(mid_one, mid_index + 1); + median = 0.5 * (*mid + *mid_one); +} +{% endhighlight %} ## Chapter 15