You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>In this week’s skeleton repository, create a <aclass="reference internal" href="2_programs_in_files.html#term-module"><spanclass="xref std std-term">module</span></a>
1130
1130
<codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">adt_examples.deque</span></code> containing a class <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Deque</span></code> implementing a
1131
1131
<aclass="reference internal" href="#term-deque"><spanclass="xref std std-term">deque</span></a>. Your implementation should use a ring buffer implemented
1132
-
as a Python list. When the <codeclass="xref py py-class docutils literal notranslate"><spanclass="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
+
<aclass="reference internal" href="3_objects.html#term-constructor"><spanclass="xref std std-term">constructor</span></a> of your <codeclass="xref py py-class docutils literal notranslate"><spanclass="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>
1136
1136
<p>Implement the following methods:</p>
1137
1137
<dlclass="simple">
1138
1138
<dt><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">append(x)</span></code></dt><dd><p>Append <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">x</span></code> to the end of the <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Deque</span></code></p>
the number of items currently in the <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Deque</span></code>.</p>
1152
1152
</dd>
1153
-
<dt><codeclass="xref py py-meth docutils literal notranslate"><spanclass="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>
1156
1153
</dl>
1157
1154
<p>In addition to the above methods, you should ensure that <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Deque</span></code>
1158
1155
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
1160
1157
<codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Deque</span></code> should not modify the <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Deque</span></code>.</p>
1161
1158
<divclass="admonition hint">
1162
1159
<pclass="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 <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">n</span></code> containing only
1164
1161
<aclass="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.9)"><codeclass="xref py py-data docutils literal notranslate"><spanclass="pre">None</span></code></a> using the following syntax:</p>
0 commit comments