Skip to content

Commit b6c9a3f

Browse files
committed
update html
1 parent 98a67f1 commit b6c9a3f

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

14_binary_search.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ <h3>Is partitioned</h3>
9898
inline
9999
bool is_partitioned(I first, I last, P pred) {
100100
first = find_if_not(first, last, pred);
101-
find_if(first, last, pred);
101+
first = find_if(first, last, pred);
102102
return first == last;
103103
}
104104
</code></pre>
@@ -151,22 +151,22 @@ <h3>Partition point</h3>
151151
Dividing numbers is easier so we will start with a counted range, instead of bounded.</p>
152152

153153
<pre><code>template&lt;typename I, typename N, typename P&gt;
154-
// I is InputIterator
155-
// P is unary predicate
154+
// I is ForwardIterator
155+
// P is UnaryPredicate
156156
// N is integral type
157157
// value_type of I == argument_type of P
158158
inline
159-
I partitioned_point_n(I first, N n, P pred) {
159+
I partition_point_n(I first, N n, P pred) {
160160
while (n) {
161161
N half = n &gt;&gt; 1;
162162
I middle = first;
163163
std::advance(middle, half);
164164
if (pred(*middle)) {
165-
n = half;
166-
} else {
167165
++middle;
168166
first = middle;
169167
n -= (half + 1);
168+
} else {
169+
n = half;
170170
}
171171
}
172172
return first;
@@ -187,12 +187,12 @@ <h3>Partition point</h3>
187187
We are also not trying to be lucky and find equal.</p>
188188

189189
<pre><code>template&lt;typename I, typename I, typename P&gt;
190-
// I is InputIterator
191-
// P is unary predicate
190+
// I is ForwardIterator
191+
// P is UnaryPredicate
192192
// N is integral type
193193
// value_type of I == argument_type of P
194194
inline
195-
I partitioned_point_n(I first, I last, P pred) {
195+
I partition_point_n(I first, I last, P pred) {
196196
return partition_point_n(first, std::distance(first, last), pred);
197197
}
198198
</code></pre>

18_binary_insertion_sort.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h2>The Organ Grinder</h2>
3333
This is a very great song by <a href="https://en.wikipedia.org/wiki/Franz_Schubert">Franz Schubert</a> but it also
3434
perfectly reflects what will go on with the course in how I feel.
3535
The song is called <a href="https://www.britannica.com/topic/Winterreise">&ldquo;The Organ Grinder&rdquo;</a> (Der Leiermann).
36-
The singer is <a href="https://en.wikipedia.org/wiki/Dietrich_Fischer-Dieskau">Dietrich fischer-dieskau</a> maybe the greatest
36+
The singer is <a href="https://en.wikipedia.org/wiki/Dietrich_Fischer-Dieskau">Dietrich Fischer-Dieskau</a> maybe the greatest
3737
leader, or art song singer of the last 50, 60, or 70 years.
3838
He started singing in the late forties.
3939
Let us spend a couple of minutes and listen to it&hellip; (<a href="https://www.youtube.com/watch?v=sIIS-UgixGE">Video here</a>)</p>
@@ -262,26 +262,25 @@ <h2>Rotate</h2>
262262
<a name="Rotate-for-bidirectional-iterators"></a>
263263
<h3>Rotate for bidirectional iterators</h3>
264264

265-
<p>Once we find where it goes, how do we make room for it?
265+
<p>Once we find where it goes (the element to insert), how do we make room for it?
266266
We &ldquo;rotate&rdquo; to the right by one.
267-
If it was a bidirectional iterator there is a beautiful algorithm.
268-
Copy is the wrong thing, because it will overwrite everything
269-
with the same value.
270-
What we want is copying from the back.
267+
If it is a bidirectional iterator there is a beautiful algorithm, copying from the back.
271268
The algorithm is called: <a href="https://en.cppreference.com/w/cpp/algorithm/copy_backward"><code>std::copy_backward</code></a>.</p>
272269

273270
<pre><code>template &lt;typename I&gt;
274271
// I is BidirectionalIterator
275272
void rotate_right_by_one(I first, I last, std::bidirectional_iterator_tag) {
276273
typedef typename std::iterator_traits&lt;I&gt;::value_type T;
277-
T butlast = last;
274+
I butlast = last;
278275
--butlast;
279276
T x = *butlast;
280277
std::copy_backward(first, butlast, last);
281278
*first = x;
282279
}
283280
</code></pre>
284281

282+
<p>Note that forward copy is the wrong thing, because it will overwrite everything with the same value (namely the first value).</p>
283+
285284
<a name="Rotate-for-forward-iterators"></a>
286285
<h3>Rotate for forward iterators</h3>
287286

@@ -355,7 +354,7 @@ <h3>Rotate for forward iterators</h3>
355354
void rotate_right_by_one(I first, I last, std::forward_iterator_tag) {
356355
if (first == last) return;
357356
I current = first;
358-
while (++current != last) std::swap(first, current);
357+
while (++current != last) std::swap(*first, *current);
359358
}
360359
</code></pre>
361360

@@ -364,8 +363,8 @@ <h3>Rotate for forward iterators</h3>
364363

365364
<pre><code>template &lt;typename I&gt;
366365
inline
367-
void rotate_right_by_one(I first, I butlast, I last) {
368-
rotate_right_by_one(first, butlast, last, typename std::iterator_traits&lt;I&gt;::iterator_category());
366+
void rotate_right_by_one(I first, I last) {
367+
rotate_right_by_one(first, last, typename std::iterator_traits&lt;I&gt;::iterator_category());
369368
}
370369
</code></pre>
371370

0 commit comments

Comments
 (0)