Skip to content

Commit 60fe701

Browse files
committed
Website build
1 parent e00974b commit 60fe701

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

5_abstract_data_types.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,10 @@ <h2><span class="section-number">5.9. </span>Exercises<a class="headerlink" href
11291129
<p>In this week’s skeleton repository, create a <a class="reference internal" href="2_programs_in_files.html#term-module"><span class="xref std std-term">module</span></a>
11301130
<code class="xref py py-mod docutils literal notranslate"><span class="pre">adt_examples.deque</span></code> containing a class <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code> implementing a
11311131
<a class="reference internal" href="#term-deque"><span class="xref std std-term">deque</span></a>. Your implementation should use a ring buffer implemented
1132-
as a Python list. When the <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code> is instantiated, the ring buffer
1133-
should have space for a few items. When it runs out of space it should
1134-
double in size. It should also halve in size when it drops to only about 40%
1135-
full.</p>
1132+
as a Python list. In order to make things somewhat simpler, we will use a
1133+
fixed size ring buffer, which doesn’t grow and shrink with the queue. The
1134+
<a class="reference internal" href="3_objects.html#term-constructor"><span class="xref std std-term">constructor</span></a> of your <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code> should take a single integer
1135+
argument which is the size of the list you will use as your ring buffer.</p>
11361136
<p>Implement the following methods:</p>
11371137
<dl class="simple">
11381138
<dt><code class="xref py py-obj docutils literal notranslate"><span class="pre">append(x)</span></code></dt><dd><p>Append <code class="xref py py-obj docutils literal notranslate"><span class="pre">x</span></code> to the end of the <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code></p>
@@ -1150,21 +1150,20 @@ <h2><span class="section-number">5.9. </span>Exercises<a class="headerlink" href
11501150
<dt><code class="xref py py-meth docutils literal notranslate"><span class="pre">__len__()</span></code></dt><dd><p>The <a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#object.__len__" title="(in Python v3.9)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__len__()</span></code></a> <a class="reference internal" href="3_objects.html#term-special-method"><span class="xref std std-term">special method</span></a>. This should return
11511151
the number of items currently in the <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code>.</p>
11521152
</dd>
1153-
<dt><code class="xref py py-meth docutils literal notranslate"><span class="pre">_size()</span></code></dt><dd><p>This should return the current length of the ring buffer, including both
1154-
occupied and empty spaces.</p>
1155-
</dd>
11561153
</dl>
11571154
<p>In addition to the above methods, you should ensure that <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code>
11581155
implements the iterator protocol. This should return the items in the queue,
1159-
starting from the end, and working backwards. Iterating over the
1156+
starting from the first to the last. Iterating over the
11601157
<code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code> should not modify the <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code>.</p>
11611158
<div class="admonition hint">
11621159
<p class="admonition-title">Hint</p>
1163-
<p>You can create a list of length 10 (for example) containing only
1160+
<p>You can create a list of length <code class="xref py py-obj docutils literal notranslate"><span class="pre">n</span></code> containing only
11641161
<a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.9)"><code class="xref py py-data docutils literal notranslate"><span class="pre">None</span></code></a> using the following syntax:</p>
1165-
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="mi">10</span>
1162+
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="n">n</span>
11661163
</pre></div>
11671164
</div>
1165+
<p>The modulo operator, <code class="xref py py-obj docutils literal notranslate"><span class="pre">%</span></code> and integer division operator <code class="xref py py-obj docutils literal notranslate"><span class="pre">//</span></code> are also likely
1166+
to be very useful.</p>
11681167
</div>
11691168
<div class="admonition hint">
11701169
<p class="admonition-title">Hint</p>

_sources/5_abstract_data_types.rst.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,10 @@ Obtain the :doc:`skeleton code for these exercises from GitHub classroom <not_re
10201020
In this week's skeleton repository, create a :term:`module`
10211021
:mod:`adt_examples.deque` containing a class :class:`Deque` implementing a
10221022
:term:`deque`. Your implementation should use a ring buffer implemented
1023-
as a Python list. When the :class:`Deque` is instantiated, the ring buffer
1024-
should have space for a few items. When it runs out of space it should
1025-
double in size. It should also halve in size when it drops to only about 40%
1026-
full.
1023+
as a Python list. In order to make things somewhat simpler, we will use a
1024+
fixed size ring buffer, which doesn't grow and shrink with the queue. The
1025+
:term:`constructor` of your :class:`Deque` should take a single integer
1026+
argument which is the size of the list you will use as your ring buffer.
10271027

10281028
Implement the following methods:
10291029

@@ -1049,23 +1049,22 @@ Obtain the :doc:`skeleton code for these exercises from GitHub classroom <not_re
10491049
The :meth:`~object.__len__` :term:`special method`. This should return
10501050
the number of items currently in the :class:`Deque`.
10511051

1052-
:meth:`_size`
1053-
This should return the current length of the ring buffer, including both
1054-
occupied and empty spaces.
1055-
10561052
In addition to the above methods, you should ensure that :class:`Deque`
10571053
implements the iterator protocol. This should return the items in the queue,
1058-
starting from the end, and working backwards. Iterating over the
1054+
starting from the first to the last. Iterating over the
10591055
:class:`Deque` should not modify the :class:`Deque`.
10601056

10611057
.. hint::
10621058

1063-
You can create a list of length 10 (for example) containing only
1059+
You can create a list of length `n` containing only
10641060
:data:`None` using the following syntax:
10651061

10661062
.. code-block:: python3
10671063
1068-
l = [None] * 10
1064+
l = [None] * n
1065+
1066+
The modulo operator, `%` and integer division operator `//` are also likely
1067+
to be very useful.
10691068

10701069
.. hint::
10711070

0 commit comments

Comments
 (0)