mirror of
https://github.com/krahets/hello-algo.git
synced 2025-02-02 22:43:50 +08:00
Update C# array code and doc
Add some comments and make code specification
This commit is contained in:
parent
064d21a55d
commit
94f66d3f06
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user