定义接口
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _001_线性表
- {
- interface IListDS<T>//定义接口
- {
- int GetLength();
- void Clear();
- bool IsEmpty();
- void Add(T item);
- void Insert(T tiem, int index);
- T 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 _001_线性表
- {
- /// <summary>
- ///
- /// </summary>
- class Program
- {
- static void Main(string[] args)
- {
- /// <summary>
- /// 使用BCL中的线性表
- /// 三个字符串具有索引的先后关系,可以通过索引访问元素
- /// </summary>
- //List<string> strList = new List<string>();
- //strList.Add("123");//0
- //strList.Add("456");//1
- //strList.Add("789");//2
- //Console.WriteLine(strList[1]);
- //strList.Remove("789");//移除
- //Console.WriteLine(strList.Count);//大小
- //strList.Clear();//清除
- //Console.WriteLine(strList.Count);
- //Console.ReadKey();
- //使用我们自己的顺序表
- SeqList<string> seqList = new SeqList<string> ();
- seqList.Add("123");
- seqList.Add("456");
- seqList.Add("789");
- Console.WriteLine(seqList.GetEle(0));
- Console.WriteLine(seqList[0]);//通过索引器
- seqList.Insert("777", 1);
- for(int i=0;i<seqList.GetLength ();i++)
- {
- Console.Write(seqList[i] + " ");
- }
- Console.WriteLine();
- seqList.Delete(0);
- seqList.Clear();
- Console.WriteLine(seqList.GetLength());
- Console.ReadKey();
- }
- }
- }
复制代码 顺序表实现方式
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |