???????????????????????????????ILSpy?????Щ.NET?????????????Щ????????????????????????????????????????ó?????????????????????????????Stack??Queue?????????
????Stack<T>?????
????Stack???????????????????????????к????????????????Push?????????Pop????????????????????.NET????????????????????????????????????????????.NET??????????????е???????????ó???????汾??????
using System;
namespace OriginalCode
{
/// <summary>
/// ????.NET??????????
/// </summary>
public class Stack<T>
{
private const int _defaultCapacity = 4;
private T[] _array;
private int _size;
public Stack()
{
//????????????????????
_array = new T[0];
//???????????????0
_size = 0;
}
/// <summary>
/// ???
/// </summary>
/// <param name="item">????????</param>
public void Push(T item)
{
if (_size == _array.Length)
{
//????洢?????????????·????????С
//??????????С??????????
T[] array = new T[_array.Length == 0 ? _defaultCapacity : 2 * _array.Length];
//???????????Copy??????????
Copy(_array?? array);
//_array?????????
_array = array;
}
_array[_size] = item;
_size += 1;
}
/// <summary>
/// ???
/// </summary>
/// <returns>????????</returns>
public T Pop()
{
if (_size == 0)
{
throw new Exception("??????????????г??????");
}
_size -= 1;
T result = _array[_size];
_array[_size] = default(T);
return result;
}
/// <summary>
/// ???????鴛?????????(?????????????????????????.NET???????C++????????Ч?????)
/// </summary>
/// <param name="oldArray">??????</param>
/// <param name="newArray">??????</param>
private void Copy(T[] oldArray?? T[] newArray)
{
for (int i = 0; i < oldArray.Length; i++)
{
newArray[i] = oldArray[i];
}
}
}
}