using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 线性表 { interface IList{ int GetLength(); void Clear(); bool IsEmpty(); void Add(T item); void Insert(T item, int index); void Delete(int index); T this[int index] { get; } T GetEle(int index); int Locate(T value); } }
顺序表实现方法:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 线性表 { class MyList:IList{ public T[] data; private int count; public MyList(int size) { data = new T[size]; count = 0; } public MyList():this(10) { } public int GetLength() { return count; } public void Clear() { count = 0; } public bool IsEmpty() { return count == 0; } public void Add(T item) { if (count == data.Length) { Console.WriteLine("当前顺序表已存满,不允许在存入"); } else { data[count] = item; count++; } } public void Insert(T item, int index) { if (index >= 0 && index= index; i--) { if (i + 1 >= data.Length) { } el