This commit is contained in:
krahets
2023-11-27 02:32:06 +08:00
parent 32d5bd97aa
commit a4a23e2488
31 changed files with 179 additions and 213 deletions

View File

@ -49,7 +49,7 @@ comments: true
```csharp title="array.cs"
/* 初始化数组 */
int[] arr = new int[5]; // { 0, 0, 0, 0, 0 }
int[] nums = { 1, 3, 2, 5, 4 };
int[] nums = [1, 3, 2, 5, 4];
```
=== "Go"

View File

@ -58,10 +58,9 @@ comments: true
```csharp title=""
/* 链表节点类 */
class ListNode {
int val; // 节点值
ListNode next; // 指向下一节点的引用
ListNode(int x) => val = x; //构造函数
class ListNode(int x) { //构造函数
int val = x; // 节点值
ListNode? next; // 指向下一节点的引用
}
```
@ -774,7 +773,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;
@ -953,7 +952,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)
@ -1162,11 +1161,10 @@ comments: true
```csharp title=""
/* 双向链表节点类 */
class ListNode {
int val; // 节点值
class ListNode(int x) { // 构造函数
int val = x; // 节点值
ListNode next; // 指向后继节点的引用
ListNode prev; // 指向前驱节点的引用
ListNode(int x) => val = x; // 构造函数
}
```

View File

@ -58,10 +58,10 @@ comments: true
```csharp title="list.cs"
/* 初始化列表 */
// 无初始值
List<int> nums1 = new();
List<int> nums1 = [];
// 有初始值
int[] numbers = new int[] { 1, 3, 2, 5, 4 };
List<int> nums = numbers.ToList();
int[] numbers = [1, 3, 2, 5, 4];
List<int> nums = [.. numbers];
```
=== "Go"
@ -704,7 +704,7 @@ comments: true
```csharp title="list.cs"
/* 拼接两个列表 */
List<int> nums1 = new() { 6, 8, 7, 10, 9 };
List<int> nums1 = [6, 8, 7, 10, 9];
nums.AddRange(nums1); // 将列表 nums1 拼接到 nums 之后
```