首先定义接口

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. java在string和int相互转化

    1 如何串 String 转换成整数 int? A. 有两种方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([St ...

  2. 笔试 - 高德软件有限公司python问题 和 答案

    高德软件有限公司python问题 和 答案 本文地址: http://blog.csdn.net/caroline_wendy/article/details/25230835 by Spike 20 ...

  3. AngularJs ng-repeat

    AngularJs ng-repeat 必须注意的性能问题 AngularJs 的 ng-repeat 让我们非常方便的遍历数组生成 Dom 元素,但是使用不当也会有性能问题. 在项目中我们使用 ng ...

  4. Android项目--XML解析

    对于xml文件,一般有两种解析方式: -----pull解析-------- -----Sax解析------- 如果xml文件是本地文件,那么就好说了 AssetManager assetManag ...

  5. requirejs的config及optimizer r.js配置

    1.怎么处理require.js这些不需要被合并的东西 所有appDir中的文件都会先copy到dir文件中,进行压缩,然后根据build.js中的配置进行相应的合并,包括img等:2.样式合并后原来 ...

  6. 构建具有深度和灵活性的安卓Wear应用

    自从去年Android 5.0发布以后就一直在关注可穿戴方面的事情.这个年的前后一直在忖度该怎么海淘一个moto 360,可是考虑到iWatch在本年度四月份发布,估计现在已经有的Android可穿戴 ...

  7. python+sublime text 2 中文乱码问题的解决方法[Decode error - output not utf-8]

    打开sublime的preferences--browse packages找到python文件夹中的Python.sublime-build文件,把它拖到sublime里打开.在最后一行加入&quo ...

  8. 使用指定格式的字符串变量格式化日期字符串,DateAndTime取时间间隔

    private void btn_GetTime_Click(object sender, EventArgs e) { lab_time.Text = DateTime.Now.ToString(& ...

  9. [译]反-反汇编 & 混淆 #1: 苹果没有遵循自己制定的Mach-O规范?

    原文地址:http://reverse.put.as/2012/02/02/anti-disassembly-obfuscation-1-apple-doesnt-follow-their-own-m ...

  10. Topics

    Topics Introduction (starting with old devices) How to handle a new Firmware How to set up your Mac ...