From 58e0a25defa1cd98349000392dd9237d0e2e717f Mon Sep 17 00:00:00 2001
From: Kister Hakusan <2753888203@qq.com>
Date: Wed, 15 Oct 2025 09:45:51 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Lesson10?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
C#进阶/C#进阶.sln | 12 +++
.../Lesson10_LinkedList.csproj | 10 ++
C#进阶/Lesson10_LinkedList/Program.cs | 99 +++++++++++++++++++
.../Lesson10_LinkedList练习.csproj | 10 ++
C#进阶/Lesson10_LinkedList练习/Program.cs | 29 ++++++
5 files changed, 160 insertions(+)
create mode 100644 C#进阶/Lesson10_LinkedList/Lesson10_LinkedList.csproj
create mode 100644 C#进阶/Lesson10_LinkedList/Program.cs
create mode 100644 C#进阶/Lesson10_LinkedList练习/Lesson10_LinkedList练习.csproj
create mode 100644 C#进阶/Lesson10_LinkedList练习/Program.cs
diff --git a/C#进阶/C#进阶.sln b/C#进阶/C#进阶.sln
index 9bbd9cc..16b732f 100644
--- a/C#进阶/C#进阶.sln
+++ b/C#进阶/C#进阶.sln
@@ -41,6 +41,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson9_顺序存储和链
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson9_顺序存储和链式存储练习", "Lesson9_顺序存储和链式存储练习\Lesson9_顺序存储和链式存储练习.csproj", "{EDA0CEB2-BB75-4149-8C0D-56C9A5286769}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_LinkedList", "Lesson10_LinkedList\Lesson10_LinkedList.csproj", "{FB78D018-414D-4F0A-8216-B65E0662A469}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson10_LinkedList练习", "Lesson10_LinkedList练习\Lesson10_LinkedList练习.csproj", "{547A4860-2E6F-4022-802A-F34204F7ADF5}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -123,6 +127,14 @@ Global
{EDA0CEB2-BB75-4149-8C0D-56C9A5286769}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDA0CEB2-BB75-4149-8C0D-56C9A5286769}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDA0CEB2-BB75-4149-8C0D-56C9A5286769}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FB78D018-414D-4F0A-8216-B65E0662A469}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FB78D018-414D-4F0A-8216-B65E0662A469}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FB78D018-414D-4F0A-8216-B65E0662A469}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FB78D018-414D-4F0A-8216-B65E0662A469}.Release|Any CPU.Build.0 = Release|Any CPU
+ {547A4860-2E6F-4022-802A-F34204F7ADF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {547A4860-2E6F-4022-802A-F34204F7ADF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {547A4860-2E6F-4022-802A-F34204F7ADF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {547A4860-2E6F-4022-802A-F34204F7ADF5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/C#进阶/Lesson10_LinkedList/Lesson10_LinkedList.csproj b/C#进阶/Lesson10_LinkedList/Lesson10_LinkedList.csproj
new file mode 100644
index 0000000..2150e37
--- /dev/null
+++ b/C#进阶/Lesson10_LinkedList/Lesson10_LinkedList.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/C#进阶/Lesson10_LinkedList/Program.cs b/C#进阶/Lesson10_LinkedList/Program.cs
new file mode 100644
index 0000000..1df3d6f
--- /dev/null
+++ b/C#进阶/Lesson10_LinkedList/Program.cs
@@ -0,0 +1,99 @@
+namespace Lesson10_LinkedList
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ #region 知识点一 LinkedList
+ //LinkedList 是一个双向链表
+ //是C#为我们封装好的一个数据结构
+ #endregion
+
+ #region 知识点二 声明
+ //需要引用命名空间 System.Collections.Generic
+
+ //链表对象,需要掌握两个类
+ //一个是链表本身 LinkedList,一个是链表节点 LinkedListNode
+
+ LinkedList linkedList = new LinkedList();
+ LinkedList linkedList2 = new LinkedList();
+ #endregion
+
+ #region 知识点三 增删查改
+
+
+ //增
+ //1.在链表尾部添加元素
+ linkedList.AddLast(1);
+ //2.在链表头部添加元素
+ linkedList.AddFirst(2);
+ //3.在某一个节点之后添加一个节点
+ // 要指定节点,先得到上一个节点
+ LinkedListNode n = linkedList.Find(1);
+ linkedList.AddAfter(n, 3);
+ //4.在某一个节点之前添加一个节点
+ // 要指定节点,先得到下一个节点
+ linkedList.AddBefore(n, 4);
+
+
+ //删
+ //1.移除头节点
+ linkedList.RemoveFirst();
+ //2.移除尾节点
+ linkedList.RemoveLast();
+ //3.移除指定节点
+ // 要指定节点,先找到节点
+ linkedList.Remove(4);//根据值移除节点
+ //4.清空
+ linkedList.Clear();
+
+ linkedList.AddFirst(1);
+ linkedList.AddLast(2);
+
+ //查
+ //1.头节点
+ LinkedListNode first = linkedList.First;
+ //2.尾节点
+ LinkedListNode last = linkedList.Last;
+ //3.查找指定节点
+ // 无法通过下标获取指定元素
+ // 只能遍历查找节点
+ LinkedListNode node = linkedList.Find(1);//根据值查找节点
+ Console.WriteLine(node.Value);
+ node = linkedList.FindLast(1);//找不到会返回空
+ //4.判断是否包含某个值
+ bool contains = linkedList.Contains(1);
+
+
+ //改
+ //先得到节点,再修改节点的值
+ Console.WriteLine(linkedList.First.Value);
+ linkedList.First.Value = 100;
+ Console.WriteLine(linkedList.First.Value);
+ #endregion
+
+ #region 知识点四 遍历
+ //1.使用foreach遍历
+ foreach (var item in linkedList)
+ {
+ Console.WriteLine(item);
+ }
+ //2.通过节点遍历
+ //从头节点开始遍历
+ LinkedListNode temp = linkedList.First;
+ while (temp != null)
+ {
+ Console.Write(temp.Value + " ");
+ temp = temp.Next;//指向下一个节点
+ }
+ //从尾节点开始遍历
+ temp = linkedList.Last;
+ while (temp != null)
+ {
+ Console.WriteLine(temp.Value + " ");
+ temp = temp.Previous;//指向上一个节点
+ }
+ #endregion
+ }
+ }
+}
diff --git a/C#进阶/Lesson10_LinkedList练习/Lesson10_LinkedList练习.csproj b/C#进阶/Lesson10_LinkedList练习/Lesson10_LinkedList练习.csproj
new file mode 100644
index 0000000..2150e37
--- /dev/null
+++ b/C#进阶/Lesson10_LinkedList练习/Lesson10_LinkedList练习.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/C#进阶/Lesson10_LinkedList练习/Program.cs b/C#进阶/Lesson10_LinkedList练习/Program.cs
new file mode 100644
index 0000000..1c417fb
--- /dev/null
+++ b/C#进阶/Lesson10_LinkedList练习/Program.cs
@@ -0,0 +1,29 @@
+namespace Lesson10_LinkedList练习
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ LinkedList ints = new LinkedList();
+ Random r = new Random();
+ for (int i = 0; i < 10; i++)
+ {
+ ints.AddLast(r.Next(1,100));
+ }
+ LinkedListNode temp = ints.First;
+ while (temp != null)
+ {
+ Console.Write(temp.Value + " ");
+ temp = temp.Next;
+ }
+ Console.WriteLine();
+ Console.WriteLine("----------------");
+ temp = ints.Last;
+ while (temp != null)
+ {
+ Console.Write(temp.Value + " ");
+ temp = temp.Previous;
+ }
+ }
+ }
+}