import{_ as a,o as l,c as p,k as s,a as o,X as n}from"./chunks/framework.6e839c56.js";const b=JSON.parse('{"title":"Queue","description":"","frontmatter":{},"headers":[],"relativePath":"api/packages/datastructure/queue.md","filePath":"api/packages/datastructure/queue.md"}'),e={name:"api/packages/datastructure/queue.md"},t=s("h1",{id:"Queue",tabindex:"-1"},[o("Queue "),s("a",{class:"header-anchor",href:"#Queue","aria-label":'Permalink to "Queue"'},"​")],-1),c=s("p",null,"队列数据结构，包括ArrayQueue, LinkedQueue, CircularQueue, and PriorityQueue。",-1),r=s("div",{STYLE:"page-break-after: always;"},null,-1),y=n('<h2 id="源码" tabindex="-1">源码 <a class="header-anchor" href="#源码" aria-label="Permalink to &quot;源码&quot;">​</a></h2><ul><li><a href="https://github.com/duke-git/lancet/blob/main/datastructure/queue/arrayqueue.go" target="_blank" rel="noreferrer">https://github.com/duke-git/lancet/blob/main/datastructure/queue/arrayqueue.go</a></li><li><a href="https://github.com/duke-git/lancet/blob/main/datastructure/queue/linkedqueue.go" target="_blank" rel="noreferrer">https://github.com/duke-git/lancet/blob/main/datastructure/queue/linkedqueue.go</a></li><li><a href="https://github.com/duke-git/lancet/blob/main/datastructure/queue/circularqueue.go" target="_blank" rel="noreferrer">https://github.com/duke-git/lancet/blob/main/datastructure/queue/circularqueue.go</a></li><li><a href="https://github.com/duke-git/lancet/blob/main/datastructure/queue/priorityqueue.go" target="_blank" rel="noreferrer">https://github.com/duke-git/lancet/blob/main/datastructure/queue/priorityqueue.go</a></li></ul>',2),F=s("div",{STYLE:"page-break-after: always;"},null,-1),i=n(`<h2 id="用法" tabindex="-1">用法 <a class="header-anchor" href="#用法" aria-label="Permalink to &quot;用法&quot;">​</a></h2><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span></code></pre></div>`,2),u=s("div",{STYLE:"page-break-after: always;"},null,-1),A=n('<h2 id="目录" tabindex="-1">目录 <a class="header-anchor" href="#目录" aria-label="Permalink to &quot;目录&quot;">​</a></h2><h3 id="_1-ArrayQueue" tabindex="-1">1. ArrayQueue <a class="header-anchor" href="#_1-ArrayQueue" aria-label="Permalink to &quot;1. ArrayQueue&quot;">​</a></h3><ul><li><a href="#NewArrayQueue">NewArrayQueue</a></li><li><a href="#ArrayQueue_Data">Data</a></li><li><a href="#ArrayQueue_Enqueue">Enqueue</a></li><li><a href="#ArrayQueue_Dequeue">Dequeue</a></li><li><a href="#ArrayQueue_Front">Front</a></li><li><a href="#ArrayQueue_Back">Back</a></li><li><a href="#ArrayQueue_Size">Size</a></li><li><a href="#ArrayQueue_IsEmpty">IsEmpty</a></li><li><a href="#ArrayQueue_IsFull">IsFull</a></li><li><a href="#ArrayQueue_Clear">Clear</a></li><li><a href="#ArrayQueue_Contain">Contain</a></li></ul><h3 id="_2-LinkedQueue" tabindex="-1">2. LinkedQueue <a class="header-anchor" href="#_2-LinkedQueue" aria-label="Permalink to &quot;2. LinkedQueue&quot;">​</a></h3><ul><li><a href="#NewLinkedQueue">NewLinkedQueue</a></li><li><a href="#LinkedQueue_Data">Data</a></li><li><a href="#LinkedQueue_Enqueue">Enqueue</a></li><li><a href="#LinkedQueue_Dequeue">Dequeue</a></li><li><a href="#LinkedQueue_Front">Front</a></li><li><a href="#LinkedQueue_Back">Back</a></li><li><a href="#LinkedQueue_Size">Size</a></li><li><a href="#LinkedQueue_IsEmpty">IsEmpty</a></li><li><a href="#LinkedQueue_Clear">Clear</a></li><li><a href="#LinkedQueue_Contain">Contain</a></li></ul><h3 id="_3-CircularQueue" tabindex="-1">3. CircularQueue <a class="header-anchor" href="#_3-CircularQueue" aria-label="Permalink to &quot;3. CircularQueue&quot;">​</a></h3><ul><li><a href="#NewCircularQueue">NewCircularQueue</a></li><li><a href="#CircularQueue_Data">Data</a></li><li><a href="#CircularQueue_Enqueue">Enqueue</a></li><li><a href="#CircularQueue_Dequeue">Dequeue</a></li><li><a href="#CircularQueue_Front">Front</a></li><li><a href="#CircularQueue_Back">Back</a></li><li><a href="#CircularQueue_Size">Size</a></li><li><a href="#CircularQueue_IsEmpty">IsEmpty</a></li><li><a href="#CircularQueue_IsFull">IsFull</a></li><li><a href="#CircularQueue_Clear">Clear</a></li><li><a href="#CircularQueue_Contain">Contain</a></li></ul><h3 id="_4-PriorityQueue" tabindex="-1">4. PriorityQueue <a class="header-anchor" href="#_4-PriorityQueue" aria-label="Permalink to &quot;4. PriorityQueue&quot;">​</a></h3><ul><li><a href="#NewPriorityQueue">NewPriorityQueue</a></li><li><a href="#PriorityQueue_Data">Data</a></li><li><a href="#PriorityQueue_Enqueue">Enqueue</a></li><li><a href="#PriorityQueue_Dequeue">Dequeue</a></li><li><a href="#PriorityQueue_IsEmpty">IsEmpty</a></li><li><a href="#PriorityQueue_IsFull">IsFull</a></li><li><a href="#PriorityQueue_Size">Size</a></li></ul>',9),E=s("div",{STYLE:"page-break-after: always;"},null,-1),d=n(`<h2 id="文档" tabindex="-1">文档 <a class="header-anchor" href="#文档" aria-label="Permalink to &quot;文档&quot;">​</a></h2><h3 id="_1-ArrayQueue-1" tabindex="-1">1. ArrayQueue <a class="header-anchor" href="#_1-ArrayQueue-1" aria-label="Permalink to &quot;1. ArrayQueue&quot;">​</a></h3><p>切片实现普通队列数据结构</p><h3 id="NewArrayQueue" tabindex="-1"><span id="NewArrayQueue">NewArrayQueue</span> <a class="header-anchor" href="#NewArrayQueue" aria-label="Permalink to &quot;&lt;span id=&quot;NewArrayQueue&quot;&gt;NewArrayQueue&lt;/span&gt;&quot;">​</a></h3><p>返回具有特定容量的ArrayQueue指针</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> NewArrayQueue[T any](capacity </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">ArrayQueue</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	items    []T</span></span>
<span class="line"><span style="color:#F6F6F4;">	head     </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">	tail     </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">	capacity </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">	size     </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">capacity </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	items    </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span>
<span class="line"><span style="color:#393A34;">	head     </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">	tail     </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">	capacity </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">	size     </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Data" tabindex="-1"><span id="ArrayQueue_Data">Data</span> <a class="header-anchor" href="#Data" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Data&quot;&gt;Data&lt;/span&gt;&quot;">​</a></h3><p>获取队列所有元素的切片</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Data</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Data</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Enqueue" tabindex="-1"><span id="ArrayQueue_Enqueue">Enqueue</span> <a class="header-anchor" href="#Enqueue" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Enqueue&quot;&gt;Enqueue&lt;/span&gt;&quot;">​</a></h3><p>元素入队列</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Enqueue</span><span style="color:#F6F6F4;">(item T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">item T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Dequeue" tabindex="-1"><span id="ArrayQueue_Dequeue">Dequeue</span> <a class="header-anchor" href="#Dequeue" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Dequeue&quot;&gt;Dequeue&lt;/span&gt;&quot;">​</a></h3><p>移除队列的头元素并返回</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Dequeue</span><span style="color:#F6F6F4;">() (T, </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Dequeue</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Dequeue</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Dequeue</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Front" tabindex="-1"><span id="ArrayQueue_Front">Front</span> <a class="header-anchor" href="#Front" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Front&quot;&gt;Front&lt;/span&gt;&quot;">​</a></h3><p>获取对列头部元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Front</span><span style="color:#F6F6F4;">() T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Front</span><span style="color:#999999;">()</span><span style="color:#393A34;"> T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Front</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Front</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Back" tabindex="-1"><span id="ArrayQueue_Back">Back</span> <a class="header-anchor" href="#Back" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Back&quot;&gt;Back&lt;/span&gt;&quot;">​</a></h3><p>获取对列尾部元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Back</span><span style="color:#F6F6F4;">() T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Back</span><span style="color:#999999;">()</span><span style="color:#393A34;"> T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Back</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Back</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Size" tabindex="-1"><span id="ArrayQueue_Size">Size</span> <a class="header-anchor" href="#Size" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Size&quot;&gt;Size&lt;/span&gt;&quot;">​</a></h3><p>获取队列元素的数量</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Size</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Size</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Size</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Size</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsEmpty" tabindex="-1"><span id="ArrayQueue_IsEmpty">IsEmpty</span> <a class="header-anchor" href="#IsEmpty" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_IsEmpty&quot;&gt;IsEmpty&lt;/span&gt;&quot;">​</a></h3><p>判断对了是否为空</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">IsEmpty</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsEmpty</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsFull" tabindex="-1"><span id="ArrayQueue_IsFull">IsFull</span> <a class="header-anchor" href="#IsFull" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_IsFull&quot;&gt;IsFull&lt;/span&gt;&quot;">​</a></h3><p>判断对了是否为满</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">IsFull</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsFull</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsFull</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsFull</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsFull</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsFull</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Clear" tabindex="-1"><span id="ArrayQueue_Clear">Clear</span> <a class="header-anchor" href="#Clear" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Clear&quot;&gt;Clear&lt;/span&gt;&quot;">​</a></h3><p>清空队列元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Clear</span><span style="color:#F6F6F4;">()</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Clear</span><span style="color:#999999;">()</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Clear</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Clear</span><span style="color:#999999;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Contain" tabindex="-1"><span id="ArrayQueue_Contain">Contain</span> <a class="header-anchor" href="#Contain" aria-label="Permalink to &quot;&lt;span id=&quot;ArrayQueue_Contain&quot;&gt;Contain&lt;/span&gt;&quot;">​</a></h3><p>判断队列是否包含某个值</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">ArrayQueue[T]) </span><span style="color:#62E884;">Contain</span><span style="color:#F6F6F4;">(value T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">ArrayQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Contain</span><span style="color:#999999;">(</span><span style="color:#393A34;">value T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewArrayQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Contain</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Contain</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewArrayQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Contain</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Contain</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="_2-LinkedQueue-1" tabindex="-1">2. LinkedQueue <a class="header-anchor" href="#_2-LinkedQueue-1" aria-label="Permalink to &quot;2. LinkedQueue&quot;">​</a></h3><p>链表实现普通队列数据结构</p><h3 id="NewLinkedQueue" tabindex="-1"><span id="NewLinkedQueue">NewLinkedQueue</span> <a class="header-anchor" href="#NewLinkedQueue" aria-label="Permalink to &quot;&lt;span id=&quot;NewLinkedQueue&quot;&gt;NewLinkedQueue&lt;/span&gt;&quot;">​</a></h3><p>返回LinkedQueue指针</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> NewLinkedQueue[T any]() </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">LinkedQueue</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	head   </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">datastructure.QueueNode[T]</span></span>
<span class="line"><span style="color:#F6F6F4;">	tail   </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">datastructure.QueueNode[T]</span></span>
<span class="line"><span style="color:#F6F6F4;">	length </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">QueueNode</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	Value T</span></span>
<span class="line"><span style="color:#F6F6F4;">	Next  </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">QueueNode[T]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	head   </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">datastructure</span><span style="color:#999999;">.</span><span style="color:#393A34;">QueueNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"><span style="color:#393A34;">	tail   </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">datastructure</span><span style="color:#999999;">.</span><span style="color:#393A34;">QueueNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"><span style="color:#393A34;">	length </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">QueueNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	Value T</span></span>
<span class="line"><span style="color:#393A34;">	Next  </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">QueueNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">]()</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">]()</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Data-1" tabindex="-1"><span id="LinkedQueue_Data">Data</span> <a class="header-anchor" href="#Data-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Data&quot;&gt;Data&lt;/span&gt;&quot;">​</a></h3><p>获取队列所有元素的切片</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Data</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Data</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">]()</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">]()</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Enqueue-1" tabindex="-1"><span id="LinkedQueue_Enqueue">Enqueue</span> <a class="header-anchor" href="#Enqueue-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Enqueue&quot;&gt;Enqueue&lt;/span&gt;&quot;">​</a></h3><p>元素入队列</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Enqueue</span><span style="color:#F6F6F4;">(value T)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">value T</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Dequeue-1" tabindex="-1"><span id="LinkedQueue_Dequeue">Dequeue</span> <a class="header-anchor" href="#Dequeue-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Dequeue&quot;&gt;Dequeue&lt;/span&gt;&quot;">​</a></h3><p>移除队列的头元素并返回</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Dequeue</span><span style="color:#F6F6F4;">() (T, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Dequeue</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Dequeue</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Dequeue</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Front-1" tabindex="-1"><span id="LinkedQueue_Front">Front</span> <a class="header-anchor" href="#Front-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Front&quot;&gt;Front&lt;/span&gt;&quot;">​</a></h3><p>获取对列头部元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Front</span><span style="color:#F6F6F4;">() (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Front</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Front</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Front</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Back-1" tabindex="-1"><span id="LinkedQueue_Back">Back</span> <a class="header-anchor" href="#Back-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Back&quot;&gt;Back&lt;/span&gt;&quot;">​</a></h3><p>获取对列尾部元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Back</span><span style="color:#F6F6F4;">() (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Back</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Back</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Back</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Size-1" tabindex="-1"><span id="LinkedQueue_Size">Size</span> <a class="header-anchor" href="#Size-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Size&quot;&gt;Size&lt;/span&gt;&quot;">​</a></h3><p>获取队列元素的数量</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Size</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Size</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Size</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Size</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsEmpty-1" tabindex="-1"><span id="LinkedQueue_IsEmpty">IsEmpty</span> <a class="header-anchor" href="#IsEmpty-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_IsEmpty&quot;&gt;IsEmpty&lt;/span&gt;&quot;">​</a></h3><p>判断对了是否为空</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">IsEmpty</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsEmpty</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Clear-1" tabindex="-1"><span id="LinkedQueue_Clear">Clear</span> <a class="header-anchor" href="#Clear-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Clear&quot;&gt;Clear&lt;/span&gt;&quot;">​</a></h3><p>清空队列元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Clear</span><span style="color:#F6F6F4;">()</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Clear</span><span style="color:#999999;">()</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Clear</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Clear</span><span style="color:#999999;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Contain-1" tabindex="-1"><span id="LinkedQueue_Contain">Contain</span> <a class="header-anchor" href="#Contain-1" aria-label="Permalink to &quot;&lt;span id=&quot;LinkedQueue_Contain&quot;&gt;Contain&lt;/span&gt;&quot;">​</a></h3><p>判断队列是否包含某个值</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">LinkedQueue[T]) </span><span style="color:#62E884;">Contain</span><span style="color:#F6F6F4;">(value T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">LinkedQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Contain</span><span style="color:#999999;">(</span><span style="color:#393A34;">value T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewLinkedQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Contain</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Contain</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewLinkedQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Contain</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Contain</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="_3-CircularQueue-1" tabindex="-1">3. CircularQueue <a class="header-anchor" href="#_3-CircularQueue-1" aria-label="Permalink to &quot;3. CircularQueue&quot;">​</a></h3><p>切片实现的循环队列.</p><h3 id="NewCircularQueue" tabindex="-1"><span id="NewCircularQueue">NewCircularQueue</span> <a class="header-anchor" href="#NewCircularQueue" aria-label="Permalink to &quot;&lt;span id=&quot;NewCircularQueue&quot;&gt;NewCircularQueue&lt;/span&gt;&quot;">​</a></h3><p>返回具有特定容量的CircularQueue指针</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> NewCircularQueue[T any](capacity </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">CircularQueue</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	data  []T</span></span>
<span class="line"><span style="color:#F6F6F4;">	front </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">	rear  </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">	capacity  </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">capacity </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	data  </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span>
<span class="line"><span style="color:#393A34;">	front </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">	rear  </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">	capacity  </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Data-2" tabindex="-1"><span id="CircularQueue_Data">Data</span> <a class="header-anchor" href="#Data-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Data&quot;&gt;Data&lt;/span&gt;&quot;">​</a></h3><p>获取队列所有元素的切片</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Data</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Data</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Enqueue-2" tabindex="-1"><span id="CircularQueue_Enqueue">Enqueue</span> <a class="header-anchor" href="#Enqueue-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Enqueue&quot;&gt;Enqueue&lt;/span&gt;&quot;">​</a></h3><p>元素入队列</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Enqueue</span><span style="color:#F6F6F4;">(value T) </span><span style="color:#97E1F1;font-style:italic;">error</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">value T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Dequeue-2" tabindex="-1"><span id="CircularQueue_Dequeue">Dequeue</span> <a class="header-anchor" href="#Dequeue-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Dequeue&quot;&gt;Dequeue&lt;/span&gt;&quot;">​</a></h3><p>移除队列的头元素并返回</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Dequeue</span><span style="color:#F6F6F4;">() (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T, </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Dequeue</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    val </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> q.</span><span style="color:#97E1F1;">Dequeue</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">val) </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">val</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> q</span><span style="color:#999999;">.</span><span style="color:#998418;">Dequeue</span><span style="color:#999999;">()</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">val</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Front-2" tabindex="-1"><span id="CircularQueue_Front">Front</span> <a class="header-anchor" href="#Front-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Front&quot;&gt;Front&lt;/span&gt;&quot;">​</a></h3><p>获取对列头部元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Front</span><span style="color:#F6F6F4;">() T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Front</span><span style="color:#999999;">()</span><span style="color:#393A34;"> T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Front</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Front</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Back-2" tabindex="-1"><span id="CircularQueue_Back">Back</span> <a class="header-anchor" href="#Back-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Back&quot;&gt;Back&lt;/span&gt;&quot;">​</a></h3><p>获取对列尾部元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Back</span><span style="color:#F6F6F4;">() T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Back</span><span style="color:#999999;">()</span><span style="color:#393A34;"> T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Back</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 1,2,3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Back</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 1,2,3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Size-2" tabindex="-1"><span id="CircularQueue_Size">Size</span> <a class="header-anchor" href="#Size-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Size&quot;&gt;Size&lt;/span&gt;&quot;">​</a></h3><p>获取队列元素的数量</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Size</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Size</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Size</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Size</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsEmpty-2" tabindex="-1"><span id="CircularQueue_IsEmpty">IsEmpty</span> <a class="header-anchor" href="#IsEmpty-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_IsEmpty&quot;&gt;IsEmpty&lt;/span&gt;&quot;">​</a></h3><p>判断对了是否为空</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">IsEmpty</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsEmpty</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsFull-1" tabindex="-1"><span id="CircularQueue_IsFull">IsFull</span> <a class="header-anchor" href="#IsFull-1" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_IsFull&quot;&gt;IsFull&lt;/span&gt;&quot;">​</a></h3><p>判断对了是否为满</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">IsFull</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsFull</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsFull</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsFull</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsFull</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsFull</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Clear-2" tabindex="-1"><span id="CircularQueue_Clear">Clear</span> <a class="header-anchor" href="#Clear-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Clear&quot;&gt;Clear&lt;/span&gt;&quot;">​</a></h3><p>清空队列元素</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Clear</span><span style="color:#F6F6F4;">()</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Clear</span><span style="color:#999999;">()</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Clear</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Clear</span><span style="color:#999999;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Contain-2" tabindex="-1"><span id="CircularQueue_Contain">Contain</span> <a class="header-anchor" href="#Contain-2" aria-label="Permalink to &quot;&lt;span id=&quot;CircularQueue_Contain&quot;&gt;Contain&lt;/span&gt;&quot;">​</a></h3><p>判断队列是否包含某个值</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CircularQueue[T]) </span><span style="color:#62E884;">Contain</span><span style="color:#F6F6F4;">(value T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CircularQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Contain</span><span style="color:#999999;">(</span><span style="color:#393A34;">value T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewCircularQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Contain</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Contain</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewCircularQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Contain</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Contain</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="_4-PriorityQueue-1" tabindex="-1">4. PriorityQueue <a class="header-anchor" href="#_4-PriorityQueue-1" aria-label="Permalink to &quot;4. PriorityQueue&quot;">​</a></h3><p>切片实现的额优先级队列。</p><h3 id="NewPriorityQueue" tabindex="-1"><span id="NewPriorityQueue">NewPriorityQueue</span> <a class="header-anchor" href="#NewPriorityQueue" aria-label="Permalink to &quot;&lt;span id=&quot;NewPriorityQueue&quot;&gt;NewPriorityQueue&lt;/span&gt;&quot;">​</a></h3><p>返回一个具有特定容量的PriorityQueue指针，参数 \`comarator\` 用于比较队列中T类型的值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> NewPriorityQueue[T any](capacity </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">, comparator lancetconstraints.Comparator) </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PriorityQueue[T]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">PriorityQueue</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	items      []T</span></span>
<span class="line"><span style="color:#F6F6F4;">	size       </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">	comparator lancetconstraints.Comparator</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">capacity </span><span style="color:#AB5959;">int</span><span style="color:#999999;">,</span><span style="color:#393A34;"> comparator lancetconstraints</span><span style="color:#999999;">.</span><span style="color:#393A34;">Comparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	items      </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span>
<span class="line"><span style="color:#393A34;">	size       </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">	comparator lancetconstraints</span><span style="color:#999999;">.</span><span style="color:#393A34;">Comparator</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewPriorityQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Data-3" tabindex="-1"><span id="PriorityQueue_Data">Data</span> <a class="header-anchor" href="#Data-3" aria-label="Permalink to &quot;&lt;span id=&quot;PriorityQueue_Data&quot;&gt;Data&lt;/span&gt;&quot;">​</a></h3><p>获取队列所有元素的切片</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PriorityQueue[T]) </span><span style="color:#62E884;">Data</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Data</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewPriorityQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Enqueue-3" tabindex="-1"><span id="PriorityQueue_Enqueue">Enqueue</span> <a class="header-anchor" href="#Enqueue-3" aria-label="Permalink to &quot;&lt;span id=&quot;PriorityQueue_Enqueue&quot;&gt;Enqueue&lt;/span&gt;&quot;">​</a></h3><p>元素入队列</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PriorityQueue[T]) </span><span style="color:#62E884;">Enqueue</span><span style="color:#F6F6F4;">(item T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">item T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    comparator </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewPriorityQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">10</span><span style="color:#F6F6F4;">, comparator)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">for</span><span style="color:#F6F6F4;"> i </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">; i </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">11</span><span style="color:#F6F6F4;">; i</span><span style="color:#F286C4;">++</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">		q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(i)</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 10, 9, 6, 7, 8, 2, 5, 1, 4, 3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">comparator</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">10</span><span style="color:#999999;">,</span><span style="color:#393A34;"> comparator</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">for</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">i</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">11</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i</span><span style="color:#AB5959;">++</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">i</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 10, 9, 6, 7, 8, 2, 5, 1, 4, 3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Dequeue-3" tabindex="-1"><span id="PriorityQueue_Dequeue">Dequeue</span> <a class="header-anchor" href="#Dequeue-3" aria-label="Permalink to &quot;&lt;span id=&quot;PriorityQueue_Dequeue&quot;&gt;Dequeue&lt;/span&gt;&quot;">​</a></h3><p>移除队列的头元素并返回</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PriorityQueue[T]) </span><span style="color:#62E884;">Dequeue</span><span style="color:#F6F6F4;">() (T, </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Dequeue</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    comparator </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewPriorityQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">10</span><span style="color:#F6F6F4;">, comparator)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">for</span><span style="color:#F6F6F4;"> i </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">; i </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">11</span><span style="color:#F6F6F4;">; i</span><span style="color:#F286C4;">++</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">		q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(i)</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">    val, ok </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> pq.</span><span style="color:#97E1F1;">Dequeue</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(val) </span><span style="color:#7B7F8B;">// 10</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Data</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 9, 8, 6, 7, 3, 2, 5, 1, 4</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">comparator</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">10</span><span style="color:#999999;">,</span><span style="color:#393A34;"> comparator</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">for</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">i</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">11</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i</span><span style="color:#AB5959;">++</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">i</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">val</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">ok</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> pq</span><span style="color:#999999;">.</span><span style="color:#998418;">Dequeue</span><span style="color:#999999;">()</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">val</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 10</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Data</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 9, 8, 6, 7, 3, 2, 5, 1, 4</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsEmpty-3" tabindex="-1"><span id="PriorityQueue_IsEmpty">IsEmpty</span> <a class="header-anchor" href="#IsEmpty-3" aria-label="Permalink to &quot;&lt;span id=&quot;PriorityQueue_IsEmpty&quot;&gt;IsEmpty&lt;/span&gt;&quot;">​</a></h3><p>判断对了是否为空</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PriorityQueue[T]) </span><span style="color:#62E884;">IsEmpty</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsEmpty</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    comparator </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewPriorityQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">10</span><span style="color:#F6F6F4;">, comparator)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">for</span><span style="color:#F6F6F4;"> i </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">; i </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">11</span><span style="color:#F6F6F4;">; i</span><span style="color:#F286C4;">++</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">		q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(i)</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">comparator</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">10</span><span style="color:#999999;">,</span><span style="color:#393A34;"> comparator</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">for</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">i</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">11</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i</span><span style="color:#AB5959;">++</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">i</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsFull-2" tabindex="-1"><span id="PriorityQueue_IsFull">IsFull</span> <a class="header-anchor" href="#IsFull-2" aria-label="Permalink to &quot;&lt;span id=&quot;PriorityQueue_IsFull&quot;&gt;IsFull&lt;/span&gt;&quot;">​</a></h3><p>判断对了是否为满</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PriorityQueue[T]) </span><span style="color:#62E884;">IsFull</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsFull</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    comparator </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewPriorityQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">10</span><span style="color:#F6F6F4;">, comparator)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsFull</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">for</span><span style="color:#F6F6F4;"> i </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">; i </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">11</span><span style="color:#F6F6F4;">; i</span><span style="color:#F286C4;">++</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">		q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(i)</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsFull</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">comparator</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">10</span><span style="color:#999999;">,</span><span style="color:#393A34;"> comparator</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsFull</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">for</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">i</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">11</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i</span><span style="color:#AB5959;">++</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">i</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsFull</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Size-3" tabindex="-1"><span id="PriorityQueue_Size">Size</span> <a class="header-anchor" href="#Size-3" aria-label="Permalink to &quot;&lt;span id=&quot;PriorityQueue_Size&quot;&gt;Size&lt;/span&gt;&quot;">​</a></h3><p>获取队列元素的数量</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (q </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PriorityQueue[T]) </span><span style="color:#62E884;">Size</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">q </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PriorityQueue</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Size</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    queue </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    comparator </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    q </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> queue.NewPriorityQueue[</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">](</span><span style="color:#BF9EEE;">10</span><span style="color:#F6F6F4;">, comparator)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">IsFull</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">for</span><span style="color:#F6F6F4;"> i </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">; i </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">; i</span><span style="color:#F286C4;">++</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">		q.</span><span style="color:#97E1F1;">Enqueue</span><span style="color:#F6F6F4;">(i)</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(q.</span><span style="color:#97E1F1;">Size</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">// 4</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">queue</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/queue</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">comparator</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">q</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> queue</span><span style="color:#999999;">.</span><span style="color:#393A34;">NewPriorityQueue</span><span style="color:#999999;">[</span><span style="color:#AB5959;">int</span><span style="color:#999999;">](</span><span style="color:#2F798A;">10</span><span style="color:#999999;">,</span><span style="color:#393A34;"> comparator</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">IsFull</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">for</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">i</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">5</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i</span><span style="color:#AB5959;">++</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		q</span><span style="color:#999999;">.</span><span style="color:#998418;">Enqueue</span><span style="color:#999999;">(</span><span style="color:#393A34;">i</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">q</span><span style="color:#999999;">.</span><span style="color:#998418;">Size</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">// 4</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div>`,243),q=[t,c,r,y,F,i,u,A,E,d];function g(m,h,v,C,f,B){return l(),p("div",null,q)}const D=a(e,[["render",g]]);export{b as __pageData,D as default};
