From 94f66d3f06557976c972bdad2203ca8c31f7abc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=BD=A4?= <1195669834@qq.com> Date: Wed, 14 Dec 2022 15:11:25 +0800 Subject: [PATCH] Update C# array code and doc Add some comments and make code specification --- codes/c#/chapter_array_and_linkedlist/Array.cs | 8 +++++++- docs/chapter_array_and_linkedlist/array.md | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/codes/c#/chapter_array_and_linkedlist/Array.cs b/codes/c#/chapter_array_and_linkedlist/Array.cs index 5afabb46..7aaa64ac 100644 --- a/codes/c#/chapter_array_and_linkedlist/Array.cs +++ b/codes/c#/chapter_array_and_linkedlist/Array.cs @@ -1,4 +1,10 @@ -namespace hello_algo.chapter_arrag_and_linkedlist +/* + * File: Array.cs + * Created Time: 2022-12-14 + * Author: mingXta (1195669834@qq.com) + */ + +namespace hello_algo.chapter_arrag_and_linkedlist { public class Array { diff --git a/docs/chapter_array_and_linkedlist/array.md b/docs/chapter_array_and_linkedlist/array.md index 0c9f796a..39273163 100644 --- a/docs/chapter_array_and_linkedlist/array.md +++ b/docs/chapter_array_and_linkedlist/array.md @@ -71,6 +71,7 @@ comments: true === "C#" ```csharp title="array.cs" + /* 初始化数组 */ int[] arr = new int[5]; // { 0, 0, 0, 0, 0 } int[] nums = { 1, 3, 2, 5, 4 }; @@ -173,7 +174,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex === "C#" ```csharp title="array.cs" - /* 随机返回一个数组元素 */ + /* 随机返回一个数组元素 */ int RandomAccess(int[] nums) { Random random=new(); @@ -282,6 +283,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex === "C#" ```csharp title="array.cs" + /* 扩展数组长度 */ int[] Extend(int[] nums, int enlarge) { // 初始化一个扩展长度后的数组 @@ -386,7 +388,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex // 将 num 赋给 index 处元素 nums[index] = num; } - + /* 删除索引 index 处元素 */ function remove(nums, index) { // 把索引 index 之后的所有元素向前移动一位 @@ -427,6 +429,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex === "C#" ```csharp title="array.cs" + /* 在数组的索引 index 处插入元素 num */ void Insert(int[] nums, int num, int index) { // 把索引 index 以及之后的所有元素向后移动一位 @@ -437,6 +440,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex // 将 num 赋给 index 处元素 nums[index] = num; } + /* 删除索引 index 处元素 */ void Remove(int[] nums, int index) { // 把索引 index 之后的所有元素向前移动一位 @@ -544,7 +548,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex === "C#" ```csharp title="array.cs" - /* 遍历数组 */ + /* 遍历数组 */ void Traverse(int[] nums) { int count = 0;