mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 06:07:20 +08:00 
			
		
		
		
	Update C# array code and doc
Add some comments and make code specification
This commit is contained in:
		@ -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
 | 
					    public class Array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
@ -71,6 +71,7 @@ comments: true
 | 
				
			|||||||
=== "C#"
 | 
					=== "C#"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```csharp title="array.cs"
 | 
					    ```csharp title="array.cs"
 | 
				
			||||||
 | 
					    /* 初始化数组 */
 | 
				
			||||||
    int[] arr = new int[5]; // { 0, 0, 0, 0, 0 }
 | 
					    int[] arr = new int[5]; // { 0, 0, 0, 0, 0 }
 | 
				
			||||||
    int[] nums = { 1, 3, 2, 5, 4 };
 | 
					    int[] nums = { 1, 3, 2, 5, 4 };
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -282,6 +283,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
 | 
				
			|||||||
=== "C#"
 | 
					=== "C#"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```csharp title="array.cs"
 | 
					    ```csharp title="array.cs"
 | 
				
			||||||
 | 
					    /* 扩展数组长度 */
 | 
				
			||||||
    int[] Extend(int[] nums, int enlarge)
 | 
					    int[] Extend(int[] nums, int enlarge)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // 初始化一个扩展长度后的数组
 | 
					        // 初始化一个扩展长度后的数组
 | 
				
			||||||
@ -427,6 +429,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
 | 
				
			|||||||
=== "C#"
 | 
					=== "C#"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```csharp title="array.cs"
 | 
					    ```csharp title="array.cs"
 | 
				
			||||||
 | 
					    /* 在数组的索引 index 处插入元素 num */
 | 
				
			||||||
    void Insert(int[] nums, int num, int index)
 | 
					    void Insert(int[] nums, int num, int index)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // 把索引 index 以及之后的所有元素向后移动一位
 | 
					        // 把索引 index 以及之后的所有元素向后移动一位
 | 
				
			||||||
@ -437,6 +440,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
 | 
				
			|||||||
        // 将 num 赋给 index 处元素
 | 
					        // 将 num 赋给 index 处元素
 | 
				
			||||||
        nums[index] = num;
 | 
					        nums[index] = num;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    /* 删除索引 index 处元素 */
 | 
				
			||||||
    void Remove(int[] nums, int index)
 | 
					    void Remove(int[] nums, int index)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // 把索引 index 之后的所有元素向前移动一位
 | 
					        // 把索引 index 之后的所有元素向前移动一位
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user