This commit is contained in:
krahets 2023-03-01 03:51:21 +08:00
parent 9cfb72d05a
commit 53b74526f2
3 changed files with 368 additions and 14 deletions

View file

@ -2175,15 +2175,118 @@
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">linkedlist_deque.cpp</span><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a> <div class="highlight"><span class="filename">linkedlist_deque.cpp</span><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a><span class="p">[</span><span class="k">class</span><span class="p">]{</span><span class="n">ListNode</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
<a id="__codelineno-11-2" name="__codelineno-11-2" href="#__codelineno-11-2"></a>
<a id="__codelineno-11-3" name="__codelineno-11-3" href="#__codelineno-11-3"></a><span class="p">[</span><span class="k">class</span><span class="p">]{</span><span class="n">LinkedListDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">linkedlist_deque.py</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a> <div class="highlight"><span class="filename">linkedlist_deque.py</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="sd">&quot;&quot;&quot; 双向链表结点 &quot;&quot;&quot;</span>
<a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="k">class</span> <span class="nc">ListNode</span><span class="p">:</span>
<a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
<a id="__codelineno-12-4" name="__codelineno-12-4" href="#__codelineno-12-4"></a> <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">=</span> <span class="n">val</span>
<a id="__codelineno-12-5" name="__codelineno-12-5" href="#__codelineno-12-5"></a> <span class="bp">self</span><span class="o">.</span><span class="n">next</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1"># 后继结点引用(指针)</span>
<a id="__codelineno-12-6" name="__codelineno-12-6" href="#__codelineno-12-6"></a> <span class="bp">self</span><span class="o">.</span><span class="n">prev</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1"># 前驱结点引用(指针)</span>
<a id="__codelineno-12-7" name="__codelineno-12-7" href="#__codelineno-12-7"></a>
<a id="__codelineno-12-8" name="__codelineno-12-8" href="#__codelineno-12-8"></a><span class="sd">&quot;&quot;&quot; 基于双向链表实现的双向队列 &quot;&quot;&quot;</span>
<a id="__codelineno-12-9" name="__codelineno-12-9" href="#__codelineno-12-9"></a><span class="k">class</span> <span class="nc">LinkedListDeque</span><span class="p">:</span>
<a id="__codelineno-12-10" name="__codelineno-12-10" href="#__codelineno-12-10"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 构造方法 &quot;&quot;&quot;</span>
<a id="__codelineno-12-11" name="__codelineno-12-11" href="#__codelineno-12-11"></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-12" name="__codelineno-12-12" href="#__codelineno-12-12"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span> <span class="c1"># 头结点 front ,尾结点 rear</span>
<a id="__codelineno-12-13" name="__codelineno-12-13" href="#__codelineno-12-13"></a> <span class="bp">self</span><span class="o">.</span><span class="n">__size</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1"># 双向队列的长度</span>
<a id="__codelineno-12-14" name="__codelineno-12-14" href="#__codelineno-12-14"></a>
<a id="__codelineno-12-15" name="__codelineno-12-15" href="#__codelineno-12-15"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 获取双向队列的长度 &quot;&quot;&quot;</span>
<a id="__codelineno-12-16" name="__codelineno-12-16" href="#__codelineno-12-16"></a> <span class="k">def</span> <span class="nf">size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-17" name="__codelineno-12-17" href="#__codelineno-12-17"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__size</span>
<a id="__codelineno-12-18" name="__codelineno-12-18" href="#__codelineno-12-18"></a>
<a id="__codelineno-12-19" name="__codelineno-12-19" href="#__codelineno-12-19"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 判断双向队列是否为空 &quot;&quot;&quot;</span>
<a id="__codelineno-12-20" name="__codelineno-12-20" href="#__codelineno-12-20"></a> <span class="k">def</span> <span class="nf">is_empty</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-21" name="__codelineno-12-21" href="#__codelineno-12-21"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span>
<a id="__codelineno-12-22" name="__codelineno-12-22" href="#__codelineno-12-22"></a>
<a id="__codelineno-12-23" name="__codelineno-12-23" href="#__codelineno-12-23"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 入队操作 &quot;&quot;&quot;</span>
<a id="__codelineno-12-24" name="__codelineno-12-24" href="#__codelineno-12-24"></a> <span class="k">def</span> <span class="nf">push</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">,</span> <span class="n">is_front</span><span class="p">):</span>
<a id="__codelineno-12-25" name="__codelineno-12-25" href="#__codelineno-12-25"></a> <span class="n">node</span> <span class="o">=</span> <span class="n">ListNode</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
<a id="__codelineno-12-26" name="__codelineno-12-26" href="#__codelineno-12-26"></a> <span class="c1"># 若链表为空,则令 front, rear 都指向 node</span>
<a id="__codelineno-12-27" name="__codelineno-12-27" href="#__codelineno-12-27"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_empty</span><span class="p">():</span>
<a id="__codelineno-12-28" name="__codelineno-12-28" href="#__codelineno-12-28"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span> <span class="o">=</span> <span class="n">node</span>
<a id="__codelineno-12-29" name="__codelineno-12-29" href="#__codelineno-12-29"></a> <span class="c1"># 队首入队操作</span>
<a id="__codelineno-12-30" name="__codelineno-12-30" href="#__codelineno-12-30"></a> <span class="k">elif</span> <span class="n">is_front</span><span class="p">:</span>
<a id="__codelineno-12-31" name="__codelineno-12-31" href="#__codelineno-12-31"></a> <span class="c1"># 将 node 添加至链表头部</span>
<a id="__codelineno-12-32" name="__codelineno-12-32" href="#__codelineno-12-32"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">.</span><span class="n">prev</span> <span class="o">=</span> <span class="n">node</span>
<a id="__codelineno-12-33" name="__codelineno-12-33" href="#__codelineno-12-33"></a> <span class="n">node</span><span class="o">.</span><span class="n">next</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">front</span>
<a id="__codelineno-12-34" name="__codelineno-12-34" href="#__codelineno-12-34"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">=</span> <span class="n">node</span> <span class="c1"># 更新头结点</span>
<a id="__codelineno-12-35" name="__codelineno-12-35" href="#__codelineno-12-35"></a> <span class="c1"># 队尾入队操作</span>
<a id="__codelineno-12-36" name="__codelineno-12-36" href="#__codelineno-12-36"></a> <span class="k">else</span><span class="p">:</span>
<a id="__codelineno-12-37" name="__codelineno-12-37" href="#__codelineno-12-37"></a> <span class="c1"># 将 node 添加至链表尾部</span>
<a id="__codelineno-12-38" name="__codelineno-12-38" href="#__codelineno-12-38"></a> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span><span class="o">.</span><span class="n">next</span> <span class="o">=</span> <span class="n">node</span>
<a id="__codelineno-12-39" name="__codelineno-12-39" href="#__codelineno-12-39"></a> <span class="n">node</span><span class="o">.</span><span class="n">prev</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span>
<a id="__codelineno-12-40" name="__codelineno-12-40" href="#__codelineno-12-40"></a> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span> <span class="o">=</span> <span class="n">node</span> <span class="c1"># 更新尾结点</span>
<a id="__codelineno-12-41" name="__codelineno-12-41" href="#__codelineno-12-41"></a> <span class="bp">self</span><span class="o">.</span><span class="n">__size</span> <span class="o">+=</span> <span class="mi">1</span> <span class="c1"># 更新队列长度</span>
<a id="__codelineno-12-42" name="__codelineno-12-42" href="#__codelineno-12-42"></a>
<a id="__codelineno-12-43" name="__codelineno-12-43" href="#__codelineno-12-43"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队首入队 &quot;&quot;&quot;</span>
<a id="__codelineno-12-44" name="__codelineno-12-44" href="#__codelineno-12-44"></a> <span class="k">def</span> <span class="nf">push_first</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">):</span>
<a id="__codelineno-12-45" name="__codelineno-12-45" href="#__codelineno-12-45"></a> <span class="bp">self</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="n">num</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<a id="__codelineno-12-46" name="__codelineno-12-46" href="#__codelineno-12-46"></a>
<a id="__codelineno-12-47" name="__codelineno-12-47" href="#__codelineno-12-47"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队尾入队 &quot;&quot;&quot;</span>
<a id="__codelineno-12-48" name="__codelineno-12-48" href="#__codelineno-12-48"></a> <span class="k">def</span> <span class="nf">push_last</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">):</span>
<a id="__codelineno-12-49" name="__codelineno-12-49" href="#__codelineno-12-49"></a> <span class="bp">self</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="n">num</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<a id="__codelineno-12-50" name="__codelineno-12-50" href="#__codelineno-12-50"></a>
<a id="__codelineno-12-51" name="__codelineno-12-51" href="#__codelineno-12-51"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 出队操作 &quot;&quot;&quot;</span>
<a id="__codelineno-12-52" name="__codelineno-12-52" href="#__codelineno-12-52"></a> <span class="k">def</span> <span class="nf">poll</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">is_front</span><span class="p">):</span>
<a id="__codelineno-12-53" name="__codelineno-12-53" href="#__codelineno-12-53"></a> <span class="c1"># 若队列为空,直接返回 None</span>
<a id="__codelineno-12-54" name="__codelineno-12-54" href="#__codelineno-12-54"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_empty</span><span class="p">():</span>
<a id="__codelineno-12-55" name="__codelineno-12-55" href="#__codelineno-12-55"></a> <span class="k">return</span> <span class="kc">None</span>
<a id="__codelineno-12-56" name="__codelineno-12-56" href="#__codelineno-12-56"></a> <span class="c1"># 队首出队操作</span>
<a id="__codelineno-12-57" name="__codelineno-12-57" href="#__codelineno-12-57"></a> <span class="k">if</span> <span class="n">is_front</span><span class="p">:</span>
<a id="__codelineno-12-58" name="__codelineno-12-58" href="#__codelineno-12-58"></a> <span class="n">val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">.</span><span class="n">val</span> <span class="c1"># 暂存头结点值</span>
<a id="__codelineno-12-59" name="__codelineno-12-59" href="#__codelineno-12-59"></a> <span class="c1"># 删除头结点</span>
<a id="__codelineno-12-60" name="__codelineno-12-60" href="#__codelineno-12-60"></a> <span class="n">fnext</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">.</span><span class="n">next</span>
<a id="__codelineno-12-61" name="__codelineno-12-61" href="#__codelineno-12-61"></a> <span class="k">if</span> <span class="n">fnext</span> <span class="o">!=</span> <span class="kc">None</span><span class="p">:</span>
<a id="__codelineno-12-62" name="__codelineno-12-62" href="#__codelineno-12-62"></a> <span class="n">fnext</span><span class="o">.</span><span class="n">prev</span> <span class="o">=</span> <span class="kc">None</span>
<a id="__codelineno-12-63" name="__codelineno-12-63" href="#__codelineno-12-63"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">.</span><span class="n">next</span> <span class="o">=</span> <span class="kc">None</span>
<a id="__codelineno-12-64" name="__codelineno-12-64" href="#__codelineno-12-64"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">=</span> <span class="n">fnext</span> <span class="c1"># 更新头结点</span>
<a id="__codelineno-12-65" name="__codelineno-12-65" href="#__codelineno-12-65"></a> <span class="c1"># 队尾出队操作</span>
<a id="__codelineno-12-66" name="__codelineno-12-66" href="#__codelineno-12-66"></a> <span class="k">else</span><span class="p">:</span>
<a id="__codelineno-12-67" name="__codelineno-12-67" href="#__codelineno-12-67"></a> <span class="n">val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span><span class="o">.</span><span class="n">val</span> <span class="c1"># 暂存尾结点值</span>
<a id="__codelineno-12-68" name="__codelineno-12-68" href="#__codelineno-12-68"></a> <span class="c1"># 删除尾结点</span>
<a id="__codelineno-12-69" name="__codelineno-12-69" href="#__codelineno-12-69"></a> <span class="n">rprev</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span><span class="o">.</span><span class="n">prev</span>
<a id="__codelineno-12-70" name="__codelineno-12-70" href="#__codelineno-12-70"></a> <span class="k">if</span> <span class="n">rprev</span> <span class="o">!=</span> <span class="kc">None</span><span class="p">:</span>
<a id="__codelineno-12-71" name="__codelineno-12-71" href="#__codelineno-12-71"></a> <span class="n">rprev</span><span class="o">.</span><span class="n">next</span> <span class="o">=</span> <span class="kc">None</span>
<a id="__codelineno-12-72" name="__codelineno-12-72" href="#__codelineno-12-72"></a> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span><span class="o">.</span><span class="n">prev</span> <span class="o">=</span> <span class="kc">None</span>
<a id="__codelineno-12-73" name="__codelineno-12-73" href="#__codelineno-12-73"></a> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span> <span class="o">=</span> <span class="n">rprev</span> <span class="c1"># 更新尾结点</span>
<a id="__codelineno-12-74" name="__codelineno-12-74" href="#__codelineno-12-74"></a> <span class="bp">self</span><span class="o">.</span><span class="n">__size</span> <span class="o">-=</span> <span class="mi">1</span> <span class="c1"># 更新队列长度</span>
<a id="__codelineno-12-75" name="__codelineno-12-75" href="#__codelineno-12-75"></a> <span class="k">return</span> <span class="n">val</span>
<a id="__codelineno-12-76" name="__codelineno-12-76" href="#__codelineno-12-76"></a>
<a id="__codelineno-12-77" name="__codelineno-12-77" href="#__codelineno-12-77"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队首出队 &quot;&quot;&quot;</span>
<a id="__codelineno-12-78" name="__codelineno-12-78" href="#__codelineno-12-78"></a> <span class="k">def</span> <span class="nf">poll_first</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-79" name="__codelineno-12-79" href="#__codelineno-12-79"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">poll</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<a id="__codelineno-12-80" name="__codelineno-12-80" href="#__codelineno-12-80"></a>
<a id="__codelineno-12-81" name="__codelineno-12-81" href="#__codelineno-12-81"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队尾出队 &quot;&quot;&quot;</span>
<a id="__codelineno-12-82" name="__codelineno-12-82" href="#__codelineno-12-82"></a> <span class="k">def</span> <span class="nf">poll_last</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-83" name="__codelineno-12-83" href="#__codelineno-12-83"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">poll</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<a id="__codelineno-12-84" name="__codelineno-12-84" href="#__codelineno-12-84"></a>
<a id="__codelineno-12-85" name="__codelineno-12-85" href="#__codelineno-12-85"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 访问队首元素 &quot;&quot;&quot;</span>
<a id="__codelineno-12-86" name="__codelineno-12-86" href="#__codelineno-12-86"></a> <span class="k">def</span> <span class="nf">peek_first</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-87" name="__codelineno-12-87" href="#__codelineno-12-87"></a> <span class="k">return</span> <span class="kc">None</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_empty</span><span class="p">()</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">.</span><span class="n">val</span>
<a id="__codelineno-12-88" name="__codelineno-12-88" href="#__codelineno-12-88"></a>
<a id="__codelineno-12-89" name="__codelineno-12-89" href="#__codelineno-12-89"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 访问队尾元素 &quot;&quot;&quot;</span>
<a id="__codelineno-12-90" name="__codelineno-12-90" href="#__codelineno-12-90"></a> <span class="k">def</span> <span class="nf">peek_last</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-91" name="__codelineno-12-91" href="#__codelineno-12-91"></a> <span class="k">return</span> <span class="kc">None</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_empty</span><span class="p">()</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">rear</span><span class="o">.</span><span class="n">val</span>
<a id="__codelineno-12-92" name="__codelineno-12-92" href="#__codelineno-12-92"></a>
<a id="__codelineno-12-93" name="__codelineno-12-93" href="#__codelineno-12-93"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 返回数组用于打印 &quot;&quot;&quot;</span>
<a id="__codelineno-12-94" name="__codelineno-12-94" href="#__codelineno-12-94"></a> <span class="k">def</span> <span class="nf">to_array</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-12-95" name="__codelineno-12-95" href="#__codelineno-12-95"></a> <span class="n">node</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">front</span>
<a id="__codelineno-12-96" name="__codelineno-12-96" href="#__codelineno-12-96"></a> <span class="n">res</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>
<a id="__codelineno-12-97" name="__codelineno-12-97" href="#__codelineno-12-97"></a> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">()):</span>
<a id="__codelineno-12-98" name="__codelineno-12-98" href="#__codelineno-12-98"></a> <span class="n">res</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">val</span>
<a id="__codelineno-12-99" name="__codelineno-12-99" href="#__codelineno-12-99"></a> <span class="n">node</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">next</span>
<a id="__codelineno-12-100" name="__codelineno-12-100" href="#__codelineno-12-100"></a> <span class="k">return</span> <span class="n">res</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">linkedlist_deque.go</span><pre><span></span><code><a id="__codelineno-13-1" name="__codelineno-13-1" href="#__codelineno-13-1"></a> <div class="highlight"><span class="filename">linkedlist_deque.go</span><pre><span></span><code><a id="__codelineno-13-1" name="__codelineno-13-1" href="#__codelineno-13-1"></a><span class="p">[</span><span class="nx">class</span><span class="p">]{</span><span class="nx">ListNode</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="kd">func</span><span class="p">]{}</span>
<a id="__codelineno-13-2" name="__codelineno-13-2" href="#__codelineno-13-2"></a>
<a id="__codelineno-13-3" name="__codelineno-13-3" href="#__codelineno-13-3"></a><span class="p">[</span><span class="nx">class</span><span class="p">]{</span><span class="nx">LinkedListDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="kd">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
@ -2437,7 +2540,9 @@
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">linkedlist_deque.c</span><pre><span></span><code><a id="__codelineno-16-1" name="__codelineno-16-1" href="#__codelineno-16-1"></a> <div class="highlight"><span class="filename">linkedlist_deque.c</span><pre><span></span><code><a id="__codelineno-16-1" name="__codelineno-16-1" href="#__codelineno-16-1"></a><span class="p">[</span><span class="n">class</span><span class="p">]{</span><span class="n">ListNode</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
<a id="__codelineno-16-2" name="__codelineno-16-2" href="#__codelineno-16-2"></a>
<a id="__codelineno-16-3" name="__codelineno-16-3" href="#__codelineno-16-3"></a><span class="p">[</span><span class="n">class</span><span class="p">]{</span><span class="n">LinkedListDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
@ -2579,7 +2684,174 @@
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">linkedlist_deque.zig</span><pre><span></span><code><a id="__codelineno-19-1" name="__codelineno-19-1" href="#__codelineno-19-1"></a> <div class="highlight"><span class="filename">linkedlist_deque.zig</span><pre><span></span><code><a id="__codelineno-19-1" name="__codelineno-19-1" href="#__codelineno-19-1"></a><span class="c1">// 双向链表结点</span>
<a id="__codelineno-19-2" name="__codelineno-19-2" href="#__codelineno-19-2"></a><span class="k">fn</span><span class="w"> </span><span class="n">ListNode</span><span class="p">(</span><span class="kr">comptime</span><span class="w"> </span><span class="n">T</span><span class="o">:</span><span class="w"> </span><span class="kt">type</span><span class="p">)</span><span class="w"> </span><span class="kt">type</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-3" name="__codelineno-19-3" href="#__codelineno-19-3"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-4" name="__codelineno-19-4" href="#__codelineno-19-4"></a><span class="w"> </span><span class="kr">const</span><span class="w"> </span><span class="n">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">@This</span><span class="p">();</span>
<a id="__codelineno-19-5" name="__codelineno-19-5" href="#__codelineno-19-5"></a>
<a id="__codelineno-19-6" name="__codelineno-19-6" href="#__codelineno-19-6"></a><span class="w"> </span><span class="n">val</span><span class="o">:</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">undefined</span><span class="p">,</span><span class="w"> </span><span class="c1">// 结点值</span>
<a id="__codelineno-19-7" name="__codelineno-19-7" href="#__codelineno-19-7"></a><span class="w"> </span><span class="n">next</span><span class="o">:</span><span class="w"> </span><span class="o">?*</span><span class="n">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span><span class="w"> </span><span class="c1">// 后继结点引用(指针)</span>
<a id="__codelineno-19-8" name="__codelineno-19-8" href="#__codelineno-19-8"></a><span class="w"> </span><span class="n">prev</span><span class="o">:</span><span class="w"> </span><span class="o">?*</span><span class="n">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span><span class="w"> </span><span class="c1">// 前驱结点引用(指针)</span>
<a id="__codelineno-19-9" name="__codelineno-19-9" href="#__codelineno-19-9"></a>
<a id="__codelineno-19-10" name="__codelineno-19-10" href="#__codelineno-19-10"></a><span class="w"> </span><span class="c1">// Initialize a list node with specific value</span>
<a id="__codelineno-19-11" name="__codelineno-19-11" href="#__codelineno-19-11"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">init</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="o">:</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-12" name="__codelineno-19-12" href="#__codelineno-19-12"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">;</span>
<a id="__codelineno-19-13" name="__codelineno-19-13" href="#__codelineno-19-13"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-14" name="__codelineno-19-14" href="#__codelineno-19-14"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">prev</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-15" name="__codelineno-19-15" href="#__codelineno-19-15"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-16" name="__codelineno-19-16" href="#__codelineno-19-16"></a><span class="w"> </span><span class="p">};</span>
<a id="__codelineno-19-17" name="__codelineno-19-17" href="#__codelineno-19-17"></a><span class="p">}</span>
<a id="__codelineno-19-18" name="__codelineno-19-18" href="#__codelineno-19-18"></a>
<a id="__codelineno-19-19" name="__codelineno-19-19" href="#__codelineno-19-19"></a><span class="c1">// 基于双向链表实现的双向队列</span>
<a id="__codelineno-19-20" name="__codelineno-19-20" href="#__codelineno-19-20"></a><span class="k">fn</span><span class="w"> </span><span class="n">LinkedListDeque</span><span class="p">(</span><span class="kr">comptime</span><span class="w"> </span><span class="n">T</span><span class="o">:</span><span class="w"> </span><span class="kt">type</span><span class="p">)</span><span class="w"> </span><span class="kt">type</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-21" name="__codelineno-19-21" href="#__codelineno-19-21"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-22" name="__codelineno-19-22" href="#__codelineno-19-22"></a><span class="w"> </span><span class="kr">const</span><span class="w"> </span><span class="n">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">@This</span><span class="p">();</span>
<a id="__codelineno-19-23" name="__codelineno-19-23" href="#__codelineno-19-23"></a>
<a id="__codelineno-19-24" name="__codelineno-19-24" href="#__codelineno-19-24"></a><span class="w"> </span><span class="n">front</span><span class="o">:</span><span class="w"> </span><span class="o">?*</span><span class="n">ListNode</span><span class="p">(</span><span class="n">T</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span><span class="w"> </span><span class="c1">// 头结点 front</span>
<a id="__codelineno-19-25" name="__codelineno-19-25" href="#__codelineno-19-25"></a><span class="w"> </span><span class="n">rear</span><span class="o">:</span><span class="w"> </span><span class="o">?*</span><span class="n">ListNode</span><span class="p">(</span><span class="n">T</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span><span class="w"> </span><span class="c1">// 尾结点 rear</span>
<a id="__codelineno-19-26" name="__codelineno-19-26" href="#__codelineno-19-26"></a><span class="w"> </span><span class="n">deqSize</span><span class="o">:</span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="c1">// 双向队列的长度</span>
<a id="__codelineno-19-27" name="__codelineno-19-27" href="#__codelineno-19-27"></a><span class="w"> </span><span class="n">mem_arena</span><span class="o">:</span><span class="w"> </span><span class="o">?</span><span class="n">std</span><span class="p">.</span><span class="n">heap</span><span class="p">.</span><span class="n">ArenaAllocator</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span>
<a id="__codelineno-19-28" name="__codelineno-19-28" href="#__codelineno-19-28"></a><span class="w"> </span><span class="n">mem_allocator</span><span class="o">:</span><span class="w"> </span><span class="n">std</span><span class="p">.</span><span class="n">mem</span><span class="p">.</span><span class="n">Allocator</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">undefined</span><span class="p">,</span><span class="w"> </span><span class="c1">// 内存分配器</span>
<a id="__codelineno-19-29" name="__codelineno-19-29" href="#__codelineno-19-29"></a>
<a id="__codelineno-19-30" name="__codelineno-19-30" href="#__codelineno-19-30"></a><span class="w"> </span><span class="c1">// 构造方法(分配内存+初始化队列)</span>
<a id="__codelineno-19-31" name="__codelineno-19-31" href="#__codelineno-19-31"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">init</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">,</span><span class="w"> </span><span class="n">allocator</span><span class="o">:</span><span class="w"> </span><span class="n">std</span><span class="p">.</span><span class="n">mem</span><span class="p">.</span><span class="n">Allocator</span><span class="p">)</span><span class="w"> </span><span class="o">!</span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-32" name="__codelineno-19-32" href="#__codelineno-19-32"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">mem_arena</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="kc">null</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-33" name="__codelineno-19-33" href="#__codelineno-19-33"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">mem_arena</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="p">.</span><span class="n">heap</span><span class="p">.</span><span class="n">ArenaAllocator</span><span class="p">.</span><span class="n">init</span><span class="p">(</span><span class="n">allocator</span><span class="p">);</span>
<a id="__codelineno-19-34" name="__codelineno-19-34" href="#__codelineno-19-34"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">mem_allocator</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">mem_arena</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">allocator</span><span class="p">();</span>
<a id="__codelineno-19-35" name="__codelineno-19-35" href="#__codelineno-19-35"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-36" name="__codelineno-19-36" href="#__codelineno-19-36"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-37" name="__codelineno-19-37" href="#__codelineno-19-37"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-38" name="__codelineno-19-38" href="#__codelineno-19-38"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">deqSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<a id="__codelineno-19-39" name="__codelineno-19-39" href="#__codelineno-19-39"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-40" name="__codelineno-19-40" href="#__codelineno-19-40"></a>
<a id="__codelineno-19-41" name="__codelineno-19-41" href="#__codelineno-19-41"></a><span class="w"> </span><span class="c1">// 析构方法(释放内存)</span>
<a id="__codelineno-19-42" name="__codelineno-19-42" href="#__codelineno-19-42"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">deinit</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-43" name="__codelineno-19-43" href="#__codelineno-19-43"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">mem_arena</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="kc">null</span><span class="p">)</span><span class="w"> </span><span class="k">return</span><span class="p">;</span>
<a id="__codelineno-19-44" name="__codelineno-19-44" href="#__codelineno-19-44"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">mem_arena</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">deinit</span><span class="p">();</span>
<a id="__codelineno-19-45" name="__codelineno-19-45" href="#__codelineno-19-45"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-46" name="__codelineno-19-46" href="#__codelineno-19-46"></a>
<a id="__codelineno-19-47" name="__codelineno-19-47" href="#__codelineno-19-47"></a><span class="w"> </span><span class="c1">// 获取双向队列的长度</span>
<a id="__codelineno-19-48" name="__codelineno-19-48" href="#__codelineno-19-48"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-49" name="__codelineno-19-49" href="#__codelineno-19-49"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">deqSize</span><span class="p">;</span>
<a id="__codelineno-19-50" name="__codelineno-19-50" href="#__codelineno-19-50"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-51" name="__codelineno-19-51" href="#__codelineno-19-51"></a>
<a id="__codelineno-19-52" name="__codelineno-19-52" href="#__codelineno-19-52"></a><span class="w"> </span><span class="c1">// 判断双向队列是否为空</span>
<a id="__codelineno-19-53" name="__codelineno-19-53" href="#__codelineno-19-53"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">isEmpty</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-54" name="__codelineno-19-54" href="#__codelineno-19-54"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<a id="__codelineno-19-55" name="__codelineno-19-55" href="#__codelineno-19-55"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-56" name="__codelineno-19-56" href="#__codelineno-19-56"></a>
<a id="__codelineno-19-57" name="__codelineno-19-57" href="#__codelineno-19-57"></a><span class="w"> </span><span class="c1">// 入队操作</span>
<a id="__codelineno-19-58" name="__codelineno-19-58" href="#__codelineno-19-58"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">push</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">,</span><span class="w"> </span><span class="n">num</span><span class="o">:</span><span class="w"> </span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">isFront</span><span class="o">:</span><span class="w"> </span><span class="kt">bool</span><span class="p">)</span><span class="w"> </span><span class="o">!</span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-59" name="__codelineno-19-59" href="#__codelineno-19-59"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">mem_allocator</span><span class="p">.</span><span class="n">create</span><span class="p">(</span><span class="n">ListNode</span><span class="p">(</span><span class="n">T</span><span class="p">));</span>
<a id="__codelineno-19-60" name="__codelineno-19-60" href="#__codelineno-19-60"></a><span class="w"> </span><span class="n">node</span><span class="p">.</span><span class="n">init</span><span class="p">(</span><span class="n">num</span><span class="p">);</span>
<a id="__codelineno-19-61" name="__codelineno-19-61" href="#__codelineno-19-61"></a><span class="w"> </span><span class="c1">// 若链表为空,则令 front, rear 都指向 node</span>
<a id="__codelineno-19-62" name="__codelineno-19-62" href="#__codelineno-19-62"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">isEmpty</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-63" name="__codelineno-19-63" href="#__codelineno-19-63"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span>
<a id="__codelineno-19-64" name="__codelineno-19-64" href="#__codelineno-19-64"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span>
<a id="__codelineno-19-65" name="__codelineno-19-65" href="#__codelineno-19-65"></a><span class="w"> </span><span class="c1">// 队首入队操作</span>
<a id="__codelineno-19-66" name="__codelineno-19-66" href="#__codelineno-19-66"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">isFront</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-67" name="__codelineno-19-67" href="#__codelineno-19-67"></a><span class="w"> </span><span class="c1">// 将 node 添加至链表头部</span>
<a id="__codelineno-19-68" name="__codelineno-19-68" href="#__codelineno-19-68"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">prev</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span>
<a id="__codelineno-19-69" name="__codelineno-19-69" href="#__codelineno-19-69"></a><span class="w"> </span><span class="n">node</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="p">;</span>
<a id="__codelineno-19-70" name="__codelineno-19-70" href="#__codelineno-19-70"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span><span class="w"> </span><span class="c1">// 更新头结点</span>
<a id="__codelineno-19-71" name="__codelineno-19-71" href="#__codelineno-19-71"></a><span class="w"> </span><span class="c1">// 队尾入队操作</span>
<a id="__codelineno-19-72" name="__codelineno-19-72" href="#__codelineno-19-72"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-73" name="__codelineno-19-73" href="#__codelineno-19-73"></a><span class="w"> </span><span class="c1">// 将 node 添加至链表尾部</span>
<a id="__codelineno-19-74" name="__codelineno-19-74" href="#__codelineno-19-74"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span>
<a id="__codelineno-19-75" name="__codelineno-19-75" href="#__codelineno-19-75"></a><span class="w"> </span><span class="n">node</span><span class="p">.</span><span class="n">prev</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="p">;</span>
<a id="__codelineno-19-76" name="__codelineno-19-76" href="#__codelineno-19-76"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span><span class="w"> </span><span class="c1">// 更新尾结点</span>
<a id="__codelineno-19-77" name="__codelineno-19-77" href="#__codelineno-19-77"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-78" name="__codelineno-19-78" href="#__codelineno-19-78"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">deqSize</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"> </span><span class="c1">// 更新队列长度</span>
<a id="__codelineno-19-79" name="__codelineno-19-79" href="#__codelineno-19-79"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span>
<a id="__codelineno-19-80" name="__codelineno-19-80" href="#__codelineno-19-80"></a>
<a id="__codelineno-19-81" name="__codelineno-19-81" href="#__codelineno-19-81"></a><span class="w"> </span><span class="c1">// 队首入队</span>
<a id="__codelineno-19-82" name="__codelineno-19-82" href="#__codelineno-19-82"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">pushFirst</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">,</span><span class="w"> </span><span class="n">num</span><span class="o">:</span><span class="w"> </span><span class="n">T</span><span class="p">)</span><span class="w"> </span><span class="o">!</span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-83" name="__codelineno-19-83" href="#__codelineno-19-83"></a><span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">num</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span><span class="p">);</span>
<a id="__codelineno-19-84" name="__codelineno-19-84" href="#__codelineno-19-84"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span>
<a id="__codelineno-19-85" name="__codelineno-19-85" href="#__codelineno-19-85"></a>
<a id="__codelineno-19-86" name="__codelineno-19-86" href="#__codelineno-19-86"></a><span class="w"> </span><span class="c1">// 队尾入队</span>
<a id="__codelineno-19-87" name="__codelineno-19-87" href="#__codelineno-19-87"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">pushLast</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">,</span><span class="w"> </span><span class="n">num</span><span class="o">:</span><span class="w"> </span><span class="n">T</span><span class="p">)</span><span class="w"> </span><span class="o">!</span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-88" name="__codelineno-19-88" href="#__codelineno-19-88"></a><span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">num</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span><span class="p">);</span>
<a id="__codelineno-19-89" name="__codelineno-19-89" href="#__codelineno-19-89"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span>
<a id="__codelineno-19-90" name="__codelineno-19-90" href="#__codelineno-19-90"></a>
<a id="__codelineno-19-91" name="__codelineno-19-91" href="#__codelineno-19-91"></a><span class="w"> </span><span class="c1">// 出队操作</span>
<a id="__codelineno-19-92" name="__codelineno-19-92" href="#__codelineno-19-92"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">poll</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">,</span><span class="w"> </span><span class="n">isFront</span><span class="o">:</span><span class="w"> </span><span class="kt">bool</span><span class="p">)</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-93" name="__codelineno-19-93" href="#__codelineno-19-93"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">isEmpty</span><span class="p">())</span><span class="w"> </span><span class="nb">@panic</span><span class="p">(</span><span class="s">&quot;双向队列为空&quot;</span><span class="p">);</span>
<a id="__codelineno-19-94" name="__codelineno-19-94" href="#__codelineno-19-94"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">val</span><span class="o">:</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">undefined</span><span class="p">;</span>
<a id="__codelineno-19-95" name="__codelineno-19-95" href="#__codelineno-19-95"></a><span class="w"> </span><span class="c1">// 队首出队操作</span>
<a id="__codelineno-19-96" name="__codelineno-19-96" href="#__codelineno-19-96"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">isFront</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-97" name="__codelineno-19-97" href="#__codelineno-19-97"></a><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">val</span><span class="p">;</span><span class="w"> </span><span class="c1">// 暂存头结点值</span>
<a id="__codelineno-19-98" name="__codelineno-19-98" href="#__codelineno-19-98"></a><span class="w"> </span><span class="c1">// 删除头结点</span>
<a id="__codelineno-19-99" name="__codelineno-19-99" href="#__codelineno-19-99"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">fNext</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">next</span><span class="p">;</span>
<a id="__codelineno-19-100" name="__codelineno-19-100" href="#__codelineno-19-100"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">fNext</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-101" name="__codelineno-19-101" href="#__codelineno-19-101"></a><span class="w"> </span><span class="n">fNext</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">prev</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-102" name="__codelineno-19-102" href="#__codelineno-19-102"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-103" name="__codelineno-19-103" href="#__codelineno-19-103"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-104" name="__codelineno-19-104" href="#__codelineno-19-104"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fNext</span><span class="p">;</span><span class="w"> </span><span class="c1">// 更新头结点</span>
<a id="__codelineno-19-105" name="__codelineno-19-105" href="#__codelineno-19-105"></a><span class="w"> </span><span class="c1">// 队尾出队操作</span>
<a id="__codelineno-19-106" name="__codelineno-19-106" href="#__codelineno-19-106"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-107" name="__codelineno-19-107" href="#__codelineno-19-107"></a><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">val</span><span class="p">;</span><span class="w"> </span><span class="c1">// 暂存尾结点值</span>
<a id="__codelineno-19-108" name="__codelineno-19-108" href="#__codelineno-19-108"></a><span class="w"> </span><span class="c1">// 删除尾结点</span>
<a id="__codelineno-19-109" name="__codelineno-19-109" href="#__codelineno-19-109"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">rPrev</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">prev</span><span class="p">;</span>
<a id="__codelineno-19-110" name="__codelineno-19-110" href="#__codelineno-19-110"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">rPrev</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-111" name="__codelineno-19-111" href="#__codelineno-19-111"></a><span class="w"> </span><span class="n">rPrev</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-112" name="__codelineno-19-112" href="#__codelineno-19-112"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">prev</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-19-113" name="__codelineno-19-113" href="#__codelineno-19-113"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-114" name="__codelineno-19-114" href="#__codelineno-19-114"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rPrev</span><span class="p">;</span><span class="w"> </span><span class="c1">// 更新尾结点</span>
<a id="__codelineno-19-115" name="__codelineno-19-115" href="#__codelineno-19-115"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-116" name="__codelineno-19-116" href="#__codelineno-19-116"></a><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">deqSize</span><span class="w"> </span><span class="o">-=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"> </span><span class="c1">// 更新队列长度</span>
<a id="__codelineno-19-117" name="__codelineno-19-117" href="#__codelineno-19-117"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
<a id="__codelineno-19-118" name="__codelineno-19-118" href="#__codelineno-19-118"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span>
<a id="__codelineno-19-119" name="__codelineno-19-119" href="#__codelineno-19-119"></a>
<a id="__codelineno-19-120" name="__codelineno-19-120" href="#__codelineno-19-120"></a><span class="w"> </span><span class="c1">// 队首出队</span>
<a id="__codelineno-19-121" name="__codelineno-19-121" href="#__codelineno-19-121"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">pollFirst</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-122" name="__codelineno-19-122" href="#__codelineno-19-122"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">poll</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
<a id="__codelineno-19-123" name="__codelineno-19-123" href="#__codelineno-19-123"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span>
<a id="__codelineno-19-124" name="__codelineno-19-124" href="#__codelineno-19-124"></a>
<a id="__codelineno-19-125" name="__codelineno-19-125" href="#__codelineno-19-125"></a><span class="w"> </span><span class="c1">// 队尾出队</span>
<a id="__codelineno-19-126" name="__codelineno-19-126" href="#__codelineno-19-126"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">pollLast</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-127" name="__codelineno-19-127" href="#__codelineno-19-127"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">poll</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span>
<a id="__codelineno-19-128" name="__codelineno-19-128" href="#__codelineno-19-128"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span>
<a id="__codelineno-19-129" name="__codelineno-19-129" href="#__codelineno-19-129"></a>
<a id="__codelineno-19-130" name="__codelineno-19-130" href="#__codelineno-19-130"></a><span class="w"> </span><span class="c1">// 访问队首元素</span>
<a id="__codelineno-19-131" name="__codelineno-19-131" href="#__codelineno-19-131"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">peekFirst</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-132" name="__codelineno-19-132" href="#__codelineno-19-132"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">isEmpty</span><span class="p">())</span><span class="w"> </span><span class="nb">@panic</span><span class="p">(</span><span class="s">&quot;双向队列为空&quot;</span><span class="p">);</span>
<a id="__codelineno-19-133" name="__codelineno-19-133" href="#__codelineno-19-133"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">val</span><span class="p">;</span>
<a id="__codelineno-19-134" name="__codelineno-19-134" href="#__codelineno-19-134"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span>
<a id="__codelineno-19-135" name="__codelineno-19-135" href="#__codelineno-19-135"></a>
<a id="__codelineno-19-136" name="__codelineno-19-136" href="#__codelineno-19-136"></a><span class="w"> </span><span class="c1">// 访问队尾元素</span>
<a id="__codelineno-19-137" name="__codelineno-19-137" href="#__codelineno-19-137"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">peekLast</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-138" name="__codelineno-19-138" href="#__codelineno-19-138"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">isEmpty</span><span class="p">())</span><span class="w"> </span><span class="nb">@panic</span><span class="p">(</span><span class="s">&quot;双向队列为空&quot;</span><span class="p">);</span>
<a id="__codelineno-19-139" name="__codelineno-19-139" href="#__codelineno-19-139"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">rear</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">val</span><span class="p">;</span>
<a id="__codelineno-19-140" name="__codelineno-19-140" href="#__codelineno-19-140"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-141" name="__codelineno-19-141" href="#__codelineno-19-141"></a>
<a id="__codelineno-19-142" name="__codelineno-19-142" href="#__codelineno-19-142"></a><span class="w"> </span><span class="c1">// 将链表转换为数组</span>
<a id="__codelineno-19-143" name="__codelineno-19-143" href="#__codelineno-19-143"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">toArray</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="o">!</span><span class="p">[]</span><span class="n">T</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-144" name="__codelineno-19-144" href="#__codelineno-19-144"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">front</span><span class="p">;</span>
<a id="__codelineno-19-145" name="__codelineno-19-145" href="#__codelineno-19-145"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">mem_allocator</span><span class="p">.</span><span class="n">alloc</span><span class="p">(</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">size</span><span class="p">());</span>
<a id="__codelineno-19-146" name="__codelineno-19-146" href="#__codelineno-19-146"></a><span class="w"> </span><span class="n">std</span><span class="p">.</span><span class="n">mem</span><span class="p">.</span><span class="n">set</span><span class="p">(</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="nb">@as</span><span class="p">(</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">));</span>
<a id="__codelineno-19-147" name="__codelineno-19-147" href="#__codelineno-19-147"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">i</span><span class="o">:</span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<a id="__codelineno-19-148" name="__codelineno-19-148" href="#__codelineno-19-148"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="n">res</span><span class="p">.</span><span class="n">len</span><span class="p">)</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-149" name="__codelineno-19-149" href="#__codelineno-19-149"></a><span class="w"> </span><span class="n">res</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">val</span><span class="p">;</span>
<a id="__codelineno-19-150" name="__codelineno-19-150" href="#__codelineno-19-150"></a><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">.</span><span class="o">?</span><span class="p">.</span><span class="n">next</span><span class="p">;</span>
<a id="__codelineno-19-151" name="__codelineno-19-151" href="#__codelineno-19-151"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-152" name="__codelineno-19-152" href="#__codelineno-19-152"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
<a id="__codelineno-19-153" name="__codelineno-19-153" href="#__codelineno-19-153"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-154" name="__codelineno-19-154" href="#__codelineno-19-154"></a>
<a id="__codelineno-19-155" name="__codelineno-19-155" href="#__codelineno-19-155"></a><span class="w"> </span><span class="c1">// 打印双向队列</span>
<a id="__codelineno-19-156" name="__codelineno-19-156" href="#__codelineno-19-156"></a><span class="w"> </span><span class="kr">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">print</span><span class="p">(</span><span class="n">self</span><span class="o">:</span><span class="w"> </span><span class="o">*</span><span class="n">Self</span><span class="p">)</span><span class="w"> </span><span class="o">!</span><span class="kt">void</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-157" name="__codelineno-19-157" href="#__codelineno-19-157"></a><span class="w"> </span><span class="kr">var</span><span class="w"> </span><span class="n">nums</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="n">self</span><span class="p">.</span><span class="n">toArray</span><span class="p">();</span>
<a id="__codelineno-19-158" name="__codelineno-19-158" href="#__codelineno-19-158"></a><span class="w"> </span><span class="n">std</span><span class="p">.</span><span class="n">debug</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;[&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">.{});</span>
<a id="__codelineno-19-159" name="__codelineno-19-159" href="#__codelineno-19-159"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">nums</span><span class="p">.</span><span class="n">len</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-160" name="__codelineno-19-160" href="#__codelineno-19-160"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">nums</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="n">num</span><span class="p">,</span><span class="w"> </span><span class="n">j</span><span class="o">|</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-161" name="__codelineno-19-161" href="#__codelineno-19-161"></a><span class="w"> </span><span class="n">std</span><span class="p">.</span><span class="n">debug</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;{}{s}&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">.{</span><span class="n">num</span><span class="p">,</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">j</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">nums</span><span class="p">.</span><span class="n">len</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="s">&quot;]&quot;</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s">&quot; &lt;-&gt; &quot;</span><span class="w"> </span><span class="p">});</span>
<a id="__codelineno-19-162" name="__codelineno-19-162" href="#__codelineno-19-162"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-163" name="__codelineno-19-163" href="#__codelineno-19-163"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-164" name="__codelineno-19-164" href="#__codelineno-19-164"></a><span class="w"> </span><span class="n">std</span><span class="p">.</span><span class="n">debug</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;]&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">.{});</span>
<a id="__codelineno-19-165" name="__codelineno-19-165" href="#__codelineno-19-165"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-166" name="__codelineno-19-166" href="#__codelineno-19-166"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-167" name="__codelineno-19-167" href="#__codelineno-19-167"></a><span class="w"> </span><span class="p">};</span>
<a id="__codelineno-19-168" name="__codelineno-19-168" href="#__codelineno-19-168"></a><span class="p">}</span>
</code></pre></div> </code></pre></div>
</div> </div>
</div> </div>
@ -2716,31 +2988,113 @@
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.cpp</span><pre><span></span><code><a id="__codelineno-21-1" name="__codelineno-21-1" href="#__codelineno-21-1"></a> <div class="highlight"><span class="filename">array_deque.cpp</span><pre><span></span><code><a id="__codelineno-21-1" name="__codelineno-21-1" href="#__codelineno-21-1"></a><span class="p">[</span><span class="k">class</span><span class="p">]{</span><span class="n">ArrayDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.py</span><pre><span></span><code><a id="__codelineno-22-1" name="__codelineno-22-1" href="#__codelineno-22-1"></a> <div class="highlight"><span class="filename">array_deque.py</span><pre><span></span><code><a id="__codelineno-22-1" name="__codelineno-22-1" href="#__codelineno-22-1"></a><span class="sd">&quot;&quot;&quot; 基于环形数组实现的双向队列 &quot;&quot;&quot;</span>
<a id="__codelineno-22-2" name="__codelineno-22-2" href="#__codelineno-22-2"></a><span class="k">class</span> <span class="nc">ArrayDeque</span><span class="p">:</span>
<a id="__codelineno-22-3" name="__codelineno-22-3" href="#__codelineno-22-3"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 构造方法 &quot;&quot;&quot;</span>
<a id="__codelineno-22-4" name="__codelineno-22-4" href="#__codelineno-22-4"></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">capacity</span><span class="p">):</span>
<a id="__codelineno-22-5" name="__codelineno-22-5" href="#__codelineno-22-5"></a> <span class="bp">self</span><span class="o">.</span><span class="n">nums</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">capacity</span>
<a id="__codelineno-22-6" name="__codelineno-22-6" href="#__codelineno-22-6"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">=</span> <span class="mi">0</span>
<a id="__codelineno-22-7" name="__codelineno-22-7" href="#__codelineno-22-7"></a> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">=</span> <span class="mi">0</span>
<a id="__codelineno-22-8" name="__codelineno-22-8" href="#__codelineno-22-8"></a>
<a id="__codelineno-22-9" name="__codelineno-22-9" href="#__codelineno-22-9"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 获取双向队列的容量 &quot;&quot;&quot;</span>
<a id="__codelineno-22-10" name="__codelineno-22-10" href="#__codelineno-22-10"></a> <span class="k">def</span> <span class="nf">capacity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-11" name="__codelineno-22-11" href="#__codelineno-22-11"></a> <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">)</span>
<a id="__codelineno-22-12" name="__codelineno-22-12" href="#__codelineno-22-12"></a>
<a id="__codelineno-22-13" name="__codelineno-22-13" href="#__codelineno-22-13"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 获取双向队列的长度 &quot;&quot;&quot;</span>
<a id="__codelineno-22-14" name="__codelineno-22-14" href="#__codelineno-22-14"></a> <span class="k">def</span> <span class="nf">size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-15" name="__codelineno-22-15" href="#__codelineno-22-15"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span>
<a id="__codelineno-22-16" name="__codelineno-22-16" href="#__codelineno-22-16"></a>
<a id="__codelineno-22-17" name="__codelineno-22-17" href="#__codelineno-22-17"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 判断双向队列是否为空 &quot;&quot;&quot;</span>
<a id="__codelineno-22-18" name="__codelineno-22-18" href="#__codelineno-22-18"></a> <span class="k">def</span> <span class="nf">is_empty</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-19" name="__codelineno-22-19" href="#__codelineno-22-19"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">==</span> <span class="mi">0</span>
<a id="__codelineno-22-20" name="__codelineno-22-20" href="#__codelineno-22-20"></a>
<a id="__codelineno-22-21" name="__codelineno-22-21" href="#__codelineno-22-21"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 计算环形数组索引 &quot;&quot;&quot;</span>
<a id="__codelineno-22-22" name="__codelineno-22-22" href="#__codelineno-22-22"></a> <span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
<a id="__codelineno-22-23" name="__codelineno-22-23" href="#__codelineno-22-23"></a> <span class="c1"># 通过取余操作实现数组首尾相连</span>
<a id="__codelineno-22-24" name="__codelineno-22-24" href="#__codelineno-22-24"></a> <span class="c1"># 当 i 越过数组尾部后,回到头部</span>
<a id="__codelineno-22-25" name="__codelineno-22-25" href="#__codelineno-22-25"></a> <span class="c1"># 当 i 越过数组头部后,回到尾部</span>
<a id="__codelineno-22-26" name="__codelineno-22-26" href="#__codelineno-22-26"></a> <span class="k">return</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">capacity</span><span class="p">())</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">capacity</span><span class="p">()</span>
<a id="__codelineno-22-27" name="__codelineno-22-27" href="#__codelineno-22-27"></a>
<a id="__codelineno-22-28" name="__codelineno-22-28" href="#__codelineno-22-28"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队首入队 &quot;&quot;&quot;</span>
<a id="__codelineno-22-29" name="__codelineno-22-29" href="#__codelineno-22-29"></a> <span class="k">def</span> <span class="nf">push_first</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">):</span>
<a id="__codelineno-22-30" name="__codelineno-22-30" href="#__codelineno-22-30"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">capacity</span><span class="p">():</span>
<a id="__codelineno-22-31" name="__codelineno-22-31" href="#__codelineno-22-31"></a> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;双向队列已满&quot;</span><span class="p">)</span>
<a id="__codelineno-22-32" name="__codelineno-22-32" href="#__codelineno-22-32"></a> <span class="k">return</span>
<a id="__codelineno-22-33" name="__codelineno-22-33" href="#__codelineno-22-33"></a> <span class="c1"># 队首指针向左移动一位</span>
<a id="__codelineno-22-34" name="__codelineno-22-34" href="#__codelineno-22-34"></a> <span class="c1"># 通过取余操作,实现 front 越过数组头部后回到尾部</span>
<a id="__codelineno-22-35" name="__codelineno-22-35" href="#__codelineno-22-35"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<a id="__codelineno-22-36" name="__codelineno-22-36" href="#__codelineno-22-36"></a> <span class="c1"># 将 num 添加至队首</span>
<a id="__codelineno-22-37" name="__codelineno-22-37" href="#__codelineno-22-37"></a> <span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="p">]</span> <span class="o">=</span> <span class="n">num</span>
<a id="__codelineno-22-38" name="__codelineno-22-38" href="#__codelineno-22-38"></a> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">+=</span> <span class="mi">1</span>
<a id="__codelineno-22-39" name="__codelineno-22-39" href="#__codelineno-22-39"></a>
<a id="__codelineno-22-40" name="__codelineno-22-40" href="#__codelineno-22-40"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队尾入队 &quot;&quot;&quot;</span>
<a id="__codelineno-22-41" name="__codelineno-22-41" href="#__codelineno-22-41"></a> <span class="k">def</span> <span class="nf">push_last</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">):</span>
<a id="__codelineno-22-42" name="__codelineno-22-42" href="#__codelineno-22-42"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">capacity</span><span class="p">():</span>
<a id="__codelineno-22-43" name="__codelineno-22-43" href="#__codelineno-22-43"></a> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;双向队列已满&quot;</span><span class="p">)</span>
<a id="__codelineno-22-44" name="__codelineno-22-44" href="#__codelineno-22-44"></a> <span class="k">return</span>
<a id="__codelineno-22-45" name="__codelineno-22-45" href="#__codelineno-22-45"></a> <span class="c1"># 计算尾指针,指向队尾索引 + 1</span>
<a id="__codelineno-22-46" name="__codelineno-22-46" href="#__codelineno-22-46"></a> <span class="n">rear</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span><span class="p">)</span>
<a id="__codelineno-22-47" name="__codelineno-22-47" href="#__codelineno-22-47"></a> <span class="c1"># 将 num 添加至队尾</span>
<a id="__codelineno-22-48" name="__codelineno-22-48" href="#__codelineno-22-48"></a> <span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="n">rear</span><span class="p">]</span> <span class="o">=</span> <span class="n">num</span>
<a id="__codelineno-22-49" name="__codelineno-22-49" href="#__codelineno-22-49"></a> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">+=</span> <span class="mi">1</span>
<a id="__codelineno-22-50" name="__codelineno-22-50" href="#__codelineno-22-50"></a>
<a id="__codelineno-22-51" name="__codelineno-22-51" href="#__codelineno-22-51"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队首出队 &quot;&quot;&quot;</span>
<a id="__codelineno-22-52" name="__codelineno-22-52" href="#__codelineno-22-52"></a> <span class="k">def</span> <span class="nf">poll_first</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-53" name="__codelineno-22-53" href="#__codelineno-22-53"></a> <span class="n">num</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">peek_first</span><span class="p">()</span>
<a id="__codelineno-22-54" name="__codelineno-22-54" href="#__codelineno-22-54"></a> <span class="c1"># 队首指针向后移动一位</span>
<a id="__codelineno-22-55" name="__codelineno-22-55" href="#__codelineno-22-55"></a> <span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<a id="__codelineno-22-56" name="__codelineno-22-56" href="#__codelineno-22-56"></a> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">-=</span> <span class="mi">1</span>
<a id="__codelineno-22-57" name="__codelineno-22-57" href="#__codelineno-22-57"></a> <span class="k">return</span> <span class="n">num</span>
<a id="__codelineno-22-58" name="__codelineno-22-58" href="#__codelineno-22-58"></a>
<a id="__codelineno-22-59" name="__codelineno-22-59" href="#__codelineno-22-59"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 队尾出队 &quot;&quot;&quot;</span>
<a id="__codelineno-22-60" name="__codelineno-22-60" href="#__codelineno-22-60"></a> <span class="k">def</span> <span class="nf">poll_last</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-61" name="__codelineno-22-61" href="#__codelineno-22-61"></a> <span class="n">num</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">peek_last</span><span class="p">()</span>
<a id="__codelineno-22-62" name="__codelineno-22-62" href="#__codelineno-22-62"></a> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">-=</span> <span class="mi">1</span>
<a id="__codelineno-22-63" name="__codelineno-22-63" href="#__codelineno-22-63"></a> <span class="k">return</span> <span class="n">num</span>
<a id="__codelineno-22-64" name="__codelineno-22-64" href="#__codelineno-22-64"></a>
<a id="__codelineno-22-65" name="__codelineno-22-65" href="#__codelineno-22-65"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 访问队首元素 &quot;&quot;&quot;</span>
<a id="__codelineno-22-66" name="__codelineno-22-66" href="#__codelineno-22-66"></a> <span class="k">def</span> <span class="nf">peek_first</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-67" name="__codelineno-22-67" href="#__codelineno-22-67"></a> <span class="k">assert</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_empty</span><span class="p">(),</span> <span class="s2">&quot;双向队列为空&quot;</span>
<a id="__codelineno-22-68" name="__codelineno-22-68" href="#__codelineno-22-68"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="p">]</span>
<a id="__codelineno-22-69" name="__codelineno-22-69" href="#__codelineno-22-69"></a>
<a id="__codelineno-22-70" name="__codelineno-22-70" href="#__codelineno-22-70"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 访问队尾元素 &quot;&quot;&quot;</span>
<a id="__codelineno-22-71" name="__codelineno-22-71" href="#__codelineno-22-71"></a> <span class="k">def</span> <span class="nf">peek_last</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-72" name="__codelineno-22-72" href="#__codelineno-22-72"></a> <span class="k">assert</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_empty</span><span class="p">(),</span> <span class="s2">&quot;双向队列为空&quot;</span>
<a id="__codelineno-22-73" name="__codelineno-22-73" href="#__codelineno-22-73"></a> <span class="c1"># 计算尾元素索引</span>
<a id="__codelineno-22-74" name="__codelineno-22-74" href="#__codelineno-22-74"></a> <span class="n">last</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">front</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">que_size</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
<a id="__codelineno-22-75" name="__codelineno-22-75" href="#__codelineno-22-75"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="n">last</span><span class="p">]</span>
<a id="__codelineno-22-76" name="__codelineno-22-76" href="#__codelineno-22-76"></a>
<a id="__codelineno-22-77" name="__codelineno-22-77" href="#__codelineno-22-77"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot; 返回数组用于打印 &quot;&quot;&quot;</span>
<a id="__codelineno-22-78" name="__codelineno-22-78" href="#__codelineno-22-78"></a> <span class="k">def</span> <span class="nf">to_array</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<a id="__codelineno-22-79" name="__codelineno-22-79" href="#__codelineno-22-79"></a> <span class="c1"># 仅转换有效长度范围内的列表元素</span>
<a id="__codelineno-22-80" name="__codelineno-22-80" href="#__codelineno-22-80"></a> <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>
<a id="__codelineno-22-81" name="__codelineno-22-81" href="#__codelineno-22-81"></a> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">que_size</span><span class="p">):</span>
<a id="__codelineno-22-82" name="__codelineno-22-82" href="#__codelineno-22-82"></a> <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">front</span><span class="o">+</span><span class="n">i</span><span class="p">)])</span>
<a id="__codelineno-22-83" name="__codelineno-22-83" href="#__codelineno-22-83"></a> <span class="k">return</span> <span class="n">res</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.go</span><pre><span></span><code><a id="__codelineno-23-1" name="__codelineno-23-1" href="#__codelineno-23-1"></a> <div class="highlight"><span class="filename">array_deque.go</span><pre><span></span><code><a id="__codelineno-23-1" name="__codelineno-23-1" href="#__codelineno-23-1"></a><span class="p">[</span><span class="nx">class</span><span class="p">]{</span><span class="nx">ArrayDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="kd">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.js</span><pre><span></span><code><a id="__codelineno-24-1" name="__codelineno-24-1" href="#__codelineno-24-1"></a> <div class="highlight"><span class="filename">array_deque.js</span><pre><span></span><code><a id="__codelineno-24-1" name="__codelineno-24-1" href="#__codelineno-24-1"></a><span class="p">[</span><span class="kd">class</span><span class="p">]{</span><span class="nx">ArrayDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="nx">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.ts</span><pre><span></span><code><a id="__codelineno-25-1" name="__codelineno-25-1" href="#__codelineno-25-1"></a> <div class="highlight"><span class="filename">array_deque.ts</span><pre><span></span><code><a id="__codelineno-25-1" name="__codelineno-25-1" href="#__codelineno-25-1"></a><span class="p">[</span><span class="kd">class</span><span class="p">]{</span><span class="nx">ArrayDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="nx">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.c</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a> <div class="highlight"><span class="filename">array_deque.c</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="p">[</span><span class="n">class</span><span class="p">]{</span><span class="n">ArrayDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.cs</span><pre><span></span><code><a id="__codelineno-27-1" name="__codelineno-27-1" href="#__codelineno-27-1"></a> <div class="highlight"><span class="filename">array_deque.cs</span><pre><span></span><code><a id="__codelineno-27-1" name="__codelineno-27-1" href="#__codelineno-27-1"></a><span class="na">[class]</span><span class="p">{</span><span class="n">ArrayDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
@ -2854,7 +3208,7 @@
</code></pre></div> </code></pre></div>
</div> </div>
<div class="tabbed-block"> <div class="tabbed-block">
<div class="highlight"><span class="filename">array_deque.zig</span><pre><span></span><code><a id="__codelineno-29-1" name="__codelineno-29-1" href="#__codelineno-29-1"></a> <div class="highlight"><span class="filename">array_deque.zig</span><pre><span></span><code><a id="__codelineno-29-1" name="__codelineno-29-1" href="#__codelineno-29-1"></a><span class="p">[</span><span class="n">class</span><span class="p">]{</span><span class="n">ArrayDeque</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{}</span>
</code></pre></div> </code></pre></div>
</div> </div>
</div> </div>

File diff suppressed because one or more lines are too long

Binary file not shown.