static void Main(string[] args) { Array1 a = new Array1(20); for (int i = 0; i < 10; i++) { a.AddLast(i); } Console.WriteLine(a); a.AddFirst(66); Console.WriteLine(a); a.Add(2, 77); Console.WriteLine(a); Console.WriteLine(a.GetFirst()); Console.WriteLine(a.GetLast()); Console.WriteLine(a.Get(1)); a.Set(1, 1000); Console.WriteLine(a); Console.Read(); }
static void Main(string[] args) { Array1 a = new Array1(20); for (int i = 0; i < 10; i++) { a.AddLast(i); } Console.WriteLine(a); a.AddFirst(66); Console.WriteLine(a); a.Add(2, 77); Console.WriteLine(a); //[66, 0, 77, 1, 2, 3, 4, 5, 6, 7, 8, 9] a.RemoveAt(2); a.RemoveFirst(); a.RemoveLast(); a.Remove(4); Console.WriteLine(a); Console.Read(); }
static void Main(string[] args) { //测试泛型数组存储任意类型的数据 int[] n = { 1, 2, 3, 4, 5, 6, 7 }; Array1 <int> a = new Array1 <int>(); for (int i = 0; i < n.Length; i++) { a.AddLast(n[i]); } Console.WriteLine(a); string[] s = { "a", "b", "c", "d" }; Array1 <string> a2 = new Array1 <string>(); for (int i = 0; i < s.Length; i++) { a2.AddLast(s[i]); } Console.WriteLine(a2); Console.Read(); }
static void Main(string[] args) { Array1 a = new Array1(10); for (int i = 0; i < 10; i++) { a.AddLast(i); } Console.WriteLine(a); a.AddLast(55); Console.WriteLine(a); for (int i = 0; i < 6; i++) { a.RemoveLast(); Console.WriteLine(a); } Console.Read(); }
//使用默认容量的数组栈 public Array1Stack() { arr = new Array1 <E>(); }
//初始化容量为capacity的数组栈 public Array1Stack(int capacity) { arr = new Array1 <E>(capacity); }
//使用默认的容量创建队列 public Array1Queue() { arr = new Array1 <E>(); }
//创建容量为capacity的队列 public Array1Queue(int capacity) { arr = new Array1 <E>(capacity); }