首先定义接口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _001_线性表
{
    interface IListDs<T>
    {
        int GetLenght();
        void Clear();
        bool isEmpty();
        void Add(T  item);
        void Insert(T item, 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>
    /// <typeparam name="T"></typeparam>
    class SeqList<T> : IListDs<T>
    {
        private T[] data; //存储数据
        private int count;//表示存了多少个数据

        public SeqList(int size)//创建数据
        {
            data = new T[size];
            count = ;
        }
        ){}//默认

        public T this[int index]
        {
            get
            {
                return GetEle(index);
            }
        }

        /// <summary>
        /// 添加元素
        /// </summary>
        /// <param name="item"></param>
        public void Add(T item)
        {
            if (count == data.Length)
            {
                Console.WriteLine("饱满了");
            }
            else
            {
                data[count] = item;
                count++;
            }
        }
        /// <summary>
        /// 清空
        /// </summary>
        public void Clear()
        {
            count = ;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public T Delete(int index)
        {
            T temp = data[index];
             && index <= count - )
            {
                ; i < count; i++)
                {
                    data[i - ] = data[i];//把数据向前移动
                }
                count--;
                return temp;
            }
            else
            {
                return default(T);
                Console.WriteLine("不存在索引");
            }
        }
        /// <summary>
        /// 获取元素
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public T GetEle(int index)
        {
             && index <= count - )
            {
                return data[index];
            }
            else
            {
                Console.WriteLine("索引不存在");
                return default(T);
            }
        }

        /// <summary>
        /// 取得数据得长度
        /// </summary>
        /// <returns></returns>
        public int GetLenght()
        {
            return count;
        }
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="item"></param>
        /// <param name="index"></param>
        public void Insert(T item, int index)
        {
             && index <= count - )
            {
                for (int i = count; i >= index; i--)
                {
                    data[i + ] = data[i];
                }
                data[index] = item;
                count++;
            }
            else
            {
                Console.WriteLine("不存在索引");
            }

        }

        public bool isEmpty()
        {
            ;
        }
        /// <summary>
        /// 数据的位置
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public int Locate(T value)
        {
            ; i < count; i++)
            {
                if (i.Equals(value))
                {
                    return i;
                }
            }
            ;
        }
    }
}

测试

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _001_线性表
{
    class Program
    {
        static void Main(string[] args)
        {
            SeqList<string> seqList = new SeqList<string>();
            seqList.Add(");
            seqList.Add("1zxc");
            seqList.Add("asd3");
            Console.WriteLine(seqList[]);
            Console.WriteLine(seqList.GetEle());

            seqList.Insert();
            ; i < seqList.GetLenght(); i++)
            {
                Console.Write(seqList[i]+" ");
            }
            Console.WriteLine();
            seqList.Delete();
            ; i < seqList.GetLenght(); i++)
            {
                Console.Write(seqList[i] + " ");
            }
            Console.WriteLine();
            seqList.Clear();
            Console.WriteLine(seqList.GetLenght());
        }
    }
}

写一个MyList的更多相关文章

  1. 用C#写一个函数,在一个数组中找出随意几个值相加等于一个值 与迭代器对比

    算法!用C#写一个函数,在一个数组中找出随意几个值相加等于一个值比如,数组{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}  要找出那些数相加等 ...

  2. 使用golang写一个redis-cli

    使用golang写一个redis-cli 0. redis通信协议 redis的客户端(redis-cli)和服务端(redis-server)的通信是建立在tcp连接之上, 两者之间数据传输的编码解 ...

  3. 用过消息队列?Kafka?能否手写一个消息队列?懵

    是否有同样的经历?面试官问你做过啥项目,我一顿胡侃,项目利用到了消息队列,kafka,rocketMQ等等. 好的,那请开始你的表演,面试官递过一支笔:给我手写一个消息队列!!WHAT? 为了大家遇到 ...

  4. 怎样写一个webpack loader

    div{display:table-cell;vertical-align:middle}#crayon-theme-info .content *{float:left}#crayon-theme- ...

  5. 请写一个php函数,可以接受任意数量的参数

    请写一个php函数,可以接受任意数量的参数 这是一道面试题.怎么写这个函数呢? function fun(......) { } ----------------------------------- ...

  6. 学记:为spring boot写一个自动配置

    spring boot遵循"约定优于配置"的原则,使用annotation对一些常规的配置项做默认配置,减少或不使用xml配置,让你的项目快速运行起来.spring boot的神奇 ...

  7. 自己写一个 jQuery 插件

    我知道这一天终将会到来,现在,它来了. 需求 开发 SharePoint 的 CSOM 应用时,经常需要在网页上输出一些信息. 这种需求和 alert 的弹窗.F12 的断点查看信息的场景是不一样的: ...

  8. 深入浅出React Native 3: 从零开始写一个Hello World

    这是深入浅出React Native的第三篇文章. 1. 环境配置 2. 我的第一个应用 将index.ios.js中的代码全部删掉,为什么要删掉呢?因为我们准备从零开始写一个应用~学习技术最好的方式 ...

  9. 【转】用C写一个简单病毒

    [摘要]在分析病毒机理的基础上,用C语言写了一个小病毒作为实例,用TURBOC2.0实现. [Abstract] This paper introduce the charateristic of t ...

随机推荐

  1. 必须掌握的JavaScript基本知识

    作为一个前端工作者,应该了解一些javascript的发展历史,javascript实现及版本等.基本概念包括语法.关键字.变量.数据类型.操作符.语句控制及函数等,它们和我们学习的其它语言C/C++ ...

  2. Ubuntu下安装Python绘图库Matplotlib的方法

    在安装好Python的基础上, sudo apt-get install python-numpy sudo apt-get install python-scipy sudo apt-get ins ...

  3. C#控件怎样获取,和失去焦点的处理

    publicForm1() { InitializeComponent(); textBox1.Enter+=newEventHandler(textBox1_Enter);//获得焦点事件 text ...

  4. 线程:ThreadLocal实现线程范围内共享变量

    在web应用中,一个请求(带有请求参数)就是一个线程,那么如何区分哪些参数属于哪个线程呢?比如struts中,A用户登录,B用户也登录,那么在Action中怎么区分哪个是A用户的数据,哪个是B用户的数 ...

  5. Day4:T1小技巧(类似于指针操作)T2搜索+小细节

    Day4:其中有很多小技巧get T1 一直没有听到过像这样的小技巧的略专业名词,有点类似于指针操作,之前有碰到过很多这样的题目 每次都是以不同的形式出现,但是感觉思想还是有点接近的吧(就比如某天有一 ...

  6. c#多选下拉框(ComboBox)

    代码如下 using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawi ...

  7. 顺手的Linux发行版及其工具推荐

    从Windows切换到Linux已经有半年多的时间了,简单给大家推荐一些个人感觉不错的软件,主要都是和开发相关的通用软件--- 0.archlinux  挑一个比较顺手的linux发行版当然是首要任务 ...

  8. TOGAF架构能力框架之架构合同、成熟度模型和架构技能框架

    TOGAF架构能力框架之架构合同.成熟度模型和架构技能框架 5. 架构合同 架构合同是在开发团体和赞助者之间关于架构的交付物.质量以及适用目标的联合协议,并且通过有效的架构治理将会促使这些协议的成功施 ...

  9. python(学习之路一)

    ''' Created on 2013-5-3 @author: lixingle ''' #输出的练习 length=3 width=4; area=length*width print(area) ...

  10. 替换__thread的一种方式,实现TLS功能

    TLS是由于多线程编程带来的产物,主要是为了解决线程资源局部化,具体内容网上有很多介绍.有很多地方已经支持了该功能,但有些地方没有,下面是GCC的一些介绍,反正具体看实际使用情况: 5.51 Thre ...