This commit is contained in:
krahets
2023-10-08 01:43:28 +08:00
parent 3d2d669b43
commit baac2d11a7
52 changed files with 999 additions and 625 deletions
@@ -252,11 +252,11 @@ comments: true
```csharp title="linked_list.cs"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个节点
ListNode n0 = new ListNode(1);
ListNode n1 = new ListNode(3);
ListNode n2 = new ListNode(2);
ListNode n3 = new ListNode(5);
ListNode n4 = new ListNode(4);
ListNode n0 = new(1);
ListNode n1 = new(3);
ListNode n2 = new(2);
ListNode n3 = new(5);
ListNode n4 = new(4);
// 构建引用指向
n0.next = n1;
n1.next = n2;
@@ -449,7 +449,7 @@ comments: true
```csharp title="linked_list.cs"
/* 在链表的节点 n0 之后插入节点 P */
void insert(ListNode n0, ListNode P) {
void Insert(ListNode n0, ListNode P) {
ListNode? n1 = n0.next;
P.next = n1;
n0.next = P;
@@ -602,7 +602,7 @@ comments: true
```csharp title="linked_list.cs"
/* 删除链表的节点 n0 之后的首个节点 */
void remove(ListNode n0) {
void Remove(ListNode n0) {
if (n0.next == null)
return;
// n0 -> P -> n1
@@ -778,7 +778,7 @@ comments: true
```csharp title="linked_list.cs"
/* 访问链表中索引为 index 的节点 */
ListNode? access(ListNode head, int index) {
ListNode? Access(ListNode head, int index) {
for (int i = 0; i < index; i++) {
if (head == null)
return null;
@@ -957,7 +957,7 @@ comments: true
```csharp title="linked_list.cs"
/* 在链表中查找值为 target 的首个节点 */
int find(ListNode head, int target) {
int Find(ListNode head, int target) {
int index = 0;
while (head != null) {
if (head.val == target)