两倍扩容机制,泛型设计,有测试代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//动态扩容顺序栈
/*
*当栈满时,两倍扩容
*/
namespace 顺序栈
{
class ArrayStack<T>
{
public T[] items;
public int Count
{
get;
private set;
}
public int Capacity
{
get;
private set;
}
public ArrayStack()
{
items = null;
Count = Capacity = 0;
}
public ArrayStack(int capacity)
{
items = new T[capacity];
Count = 0;
Capacity = capacity;
}
public ArrayStack(T[] items)
{
this.items = items;
Count = 0;
Capacity = items.Length;
}
public T Pop()
{
if(Count =