<aid="__codelineno-14-13"name="__codelineno-14-13"href="#__codelineno-14-13"></a><spanclass="w"></span><spanclass="sd">"""获取索引为 i 节点的值"""</span>
<aid="__codelineno-14-13"name="__codelineno-14-13"href="#__codelineno-14-13"></a><spanclass="w"></span><spanclass="sd">"""获取索引为 i 节点的值"""</span>
<aid="__codelineno-0-7"name="__codelineno-0-7"href="#__codelineno-0-7"></a><spanclass="n">deque</span><spanclass="o">.</span><spanclass="n">append</span><spanclass="p">(</span><spanclass="mi">2</span><spanclass="p">)</span><spanclass="c1"># Add to the tail</span>
<aid="__codelineno-0-7"name="__codelineno-0-7"href="#__codelineno-0-7"></a><spanclass="n">deq</span><spanclass="o">.</span><spanclass="n">append</span><spanclass="p">(</span><spanclass="mi">2</span><spanclass="p">)</span><spanclass="c1"># Add to the tail</span>
<aid="__codelineno-0-10"name="__codelineno-0-10"href="#__codelineno-0-10"></a><spanclass="n">deque</span><spanclass="o">.</span><spanclass="n">appendleft</span><spanclass="p">(</span><spanclass="mi">3</span><spanclass="p">)</span><spanclass="c1"># Add to the head</span>
<aid="__codelineno-0-10"name="__codelineno-0-10"href="#__codelineno-0-10"></a><spanclass="n">deq</span><spanclass="o">.</span><spanclass="n">appendleft</span><spanclass="p">(</span><spanclass="mi">3</span><spanclass="p">)</span><spanclass="c1"># Add to the head</span>
<aid="__codelineno-0-14"name="__codelineno-0-14"href="#__codelineno-0-14"></a><spanclass="n">front</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deque</span><spanclass="p">[</span><spanclass="mi">0</span><spanclass="p">]</span><spanclass="c1"># The first element</span>
<aid="__codelineno-0-14"name="__codelineno-0-14"href="#__codelineno-0-14"></a><spanclass="n">front</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deq</span><spanclass="p">[</span><spanclass="mi">0</span><spanclass="p">]</span><spanclass="c1"># The first element</span>
<aid="__codelineno-0-15"name="__codelineno-0-15"href="#__codelineno-0-15"></a><spanclass="n">rear</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deque</span><spanclass="p">[</span><spanclass="o">-</span><spanclass="mi">1</span><spanclass="p">]</span><spanclass="c1"># The last element</span>
<aid="__codelineno-0-15"name="__codelineno-0-15"href="#__codelineno-0-15"></a><spanclass="n">rear</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deq</span><spanclass="p">[</span><spanclass="o">-</span><spanclass="mi">1</span><spanclass="p">]</span><spanclass="c1"># The last element</span>
<aid="__codelineno-0-18"name="__codelineno-0-18"href="#__codelineno-0-18"></a><spanclass="n">pop_front</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deque</span><spanclass="o">.</span><spanclass="n">popleft</span><spanclass="p">()</span><spanclass="c1"># The first element dequeued</span>
<aid="__codelineno-0-18"name="__codelineno-0-18"href="#__codelineno-0-18"></a><spanclass="n">pop_front</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deq</span><spanclass="o">.</span><spanclass="n">popleft</span><spanclass="p">()</span><spanclass="c1"># The first element dequeued</span>
<aid="__codelineno-0-19"name="__codelineno-0-19"href="#__codelineno-0-19"></a><spanclass="n">pop_rear</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deque</span><spanclass="o">.</span><spanclass="n">pop</span><spanclass="p">()</span><spanclass="c1"># The last element dequeued</span>
<aid="__codelineno-0-19"name="__codelineno-0-19"href="#__codelineno-0-19"></a><spanclass="n">pop_rear</span><spanclass="p">:</span><spanclass="nb">int</span><spanclass="o">=</span><spanclass="n">deq</span><spanclass="o">.</span><spanclass="n">pop</span><spanclass="p">()</span><spanclass="c1"># The last element dequeued</span>
<aid="__codelineno-14-13"name="__codelineno-14-13"href="#__codelineno-14-13"></a><spanclass="w"></span><spanclass="sd">"""获取索引为 i 节点的值"""</span>
<aid="__codelineno-14-13"name="__codelineno-14-13"href="#__codelineno-14-13"></a><spanclass="w"></span><spanclass="sd">"""获取索引为 i 节点的值"""</span>
<aid="__codelineno-14-13"name="__codelineno-14-13"href="#__codelineno-14-13"></a><spanclass="w"></span><spanclass="sd">"""獲取索引為 i 節點的值"""</span>
<aid="__codelineno-14-13"name="__codelineno-14-13"href="#__codelineno-14-13"></a><spanclass="w"></span><spanclass="sd">"""獲取索引為 i 節點的值"""</span>