From d8bf0b02d163bde9b3ae90640a63fd0d66b8a1dd Mon Sep 17 00:00:00 2001 From: moonache <476681765@qq.com> Date: Fri, 30 Dec 2022 14:28:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20C#=20=E5=86=85?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E5=8F=8C=E5=90=91=E9=98=9F=E5=88=97=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RT --- docs/chapter_stack_and_queue/deque.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/chapter_stack_and_queue/deque.md b/docs/chapter_stack_and_queue/deque.md index ca55f8223..41d9f4498 100644 --- a/docs/chapter_stack_and_queue/deque.md +++ b/docs/chapter_stack_and_queue/deque.md @@ -167,5 +167,28 @@ comments: true === "C#" ```csharp title="deque.cs" + /* 初始化双向队列 */ + /* LinkedList 是 C# 中使用双向链表实现的双向队列 */ + LinkedList deque = new LinkedList(); + /* 元素入队 */ + deque.AddLast(2); // 添加至队尾 + deque.AddLast(5); + deque.AddLast(4); + deque.AddFirst(3); // 添加至队首 + deque.AddFirst(1); + + /* 访问元素 */ + int peekFirst = deque.First.Value; // 队首元素 + int peekLast = deque.Last.Value; // 队尾元素 + + /* 元素出队 */ + deque.RemoveFirst(); // 队首元素出队 + deque.RemoveLast(); // 队尾元素出队 + + /* 获取双向队列的长度 */ + int size = deque.Count; + + /* 判断双向队列是否为空 */ + bool isEmpty = deque.Count == 0; ``` From 56b6bf10f84d420fa70e74d995337ced04295110 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Fri, 30 Dec 2022 16:11:47 +0800 Subject: [PATCH 2/2] Update deque.md --- docs/chapter_stack_and_queue/deque.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/chapter_stack_and_queue/deque.md b/docs/chapter_stack_and_queue/deque.md index 41d9f4498..72106360f 100644 --- a/docs/chapter_stack_and_queue/deque.md +++ b/docs/chapter_stack_and_queue/deque.md @@ -168,7 +168,7 @@ comments: true ```csharp title="deque.cs" /* 初始化双向队列 */ - /* LinkedList 是 C# 中使用双向链表实现的双向队列 */ + // 在 C# 中,将链表 LinkedList 看作双向队列来使用 LinkedList deque = new LinkedList(); /* 元素入队 */