这是原文
这是我自己写的简易版
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public class SqlList<T>//顺序表
{
int maxSize;
public T[] data ;
int last;
public void Insert(T e)//插入元素
{
if (last < maxSize)
{
last++;
data[last] = e;
}
else
{
Console.WriteLine("顺序表已满");
}
}
public void Delete()//删除元素
{
data[last] = default(T);
last--;
}
public void Locate(T element)//确定元素在顺序表中位置
{
for (int i = 0; i < last; i++)
{
if (data[i].Equals(element))
{
Console.WriteLine("{0}在顺序表第{1}元素中",element, i+1);
}
}
}
public void Indexing()//检索元素
{
for (int i = 0; i <= last; i++)
{
Console.Write("{0}", data[i]);
}
}
public void Empty()//清空表
{
for (int i = 0; i < last; i++)
{
data[i] = default(T);
}
last = -1;
}
public void IsEmpty()//判断表是否为空
{
if (last == -1)
{
Console.WriteLine("表为空");
}
else
{
Console.WriteLine("表不空");
}
}
public SqlList(int size)
{
data = new T[size];
maxSize = size;
last = -1;
}
}
static void Main(string[] args)
{
SqlList<string> sql = new SqlList<string>(10);
sql.IsEmpty();
sql.Insert("a");
sql.Insert("b");
sql.Insert("1");
sql.Insert("2");
sql.Insert("4");
sql.Insert("6");
sql.Insert("4");
sql.IsEmpty();
sql.Indexing();
Console.Write("\n");
sql.Delete();
sql.Indexing();
Console.Write("\n");
sql.Locate("1");
sql.Empty();
sql.IsEmpty();
Console.ReadKey();
}
}
}