arr
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Algorithm
{
internal class MyList
{
private int[] arr;
private int arrCapacity = 10;
private int arrSize = 0;
private readonly int extendRatio = 2;
public MyList()
{
arr = new int[arrCapacity];
}
public int Size()
{
return arrSize;
}
public int Capacity()
{
return arrCapacity;
}
public int Get(int index)
{
if(index<0|| index >= arrSize)
{
throw new IndexOutOfRangeException($"索引越界,current index is: {index}");
}
return arr[index];
}
public void Set(int index, int num)
{
if (index < 0 || index >= arrSize)
{
throw new IndexOutOfRangeException($"索引越界,current index is: {index}");
}
arr[index] = num;
}
public void Add(int num)
{
if (arrSize == arrCapacity)
{
ExtendCapacity();
}
arr[arrSize]= num;
arrSize++;
}
public void Insert(int index, int num)
{
if(index< 0 || index >= arrSize)
{
throw new IndexOutOfRangeException($"索引越界,current index is: {index}");
}
if(arrSize == arrCapacity)
{
ExtendCapacity();
}
for(int Count=arr.Length-1; Count >= index; Count--)
{
arr[Count+1] = arr[Count];
}
arr[index]=num;
arrSize++;
}
public int Remove(int index)
{
}
}
}