zoukankan      html  css  js  c++  java
  • C#数据结构之线性表

    一、概念:略

    二、用接口的形式表示线性表:

      public interface IListThread<T>

      {

        //线性表中的基本方法

        int Getlength();

        void Clear();

        bool IsEmpty();

        void Append(T item);

        void Insert(T item,int i);

        T Delete(int i);

        T GetElement(T value);

        int Locate(T value);

      }

      (1)、顺序表(地址连续的空间):表中相邻的数据元素在内存中的存储位置也相邻。用SeqList<T>类来实现接口IListThread<T>

      public class SeqList<T>:IListThread<T>

      {

        private int MaxSize;//最大容量

        private T[] data; //用于存放线性表的数据元素

        private int last;  //顺序表最后一个元素的位置

        

        //索引器

        public T this[int index]

        {

          get{return data[index];}

          set{data[index]=value;}

        }

        //获得最后一个元素的位置

        public int Last

        {

          get{return last;}

        }

        //线性表容量

        public int Maxsize

        {

          get{return MaxSize;}

          set{MaxSize=value;}

        }

        //构造函数

        public SeqList(int size)

        {

          data=new T[size];

          MaxSize=size;

          last=-1;

        }

        //长度

        public int GetLength()

        {

          return last+1;

        }

        //清空

        .......

        last=-1;

        //判断是否为空

        public bool IsEmpty()

        {

          if(last==-1)

          {

            return true;

          }

          else

          {

            return false;

          }

        }

        public bool IsFull()

        {

          if(last==MaxSize-1)

          {

            return true;

          }

          else

          {

            return false;

          }

        }

        //追加元素

          public void Append(T item)

        {

          if(IsFull())

          {

            return;

          }

          else

          {

            data[++last]=item;

          }

        }

    //追加元素时判断是否满了,插入数据时判断位置、是否已满,

      }

  • 相关阅读:
    MiniUI表单验证实践
    MiniUI官方表单验证示例
    MiniUI表单验证总结
    Js-事件分发与DOM事件流
    Windows远程桌面连接的利器-mRemote
    Git 以分支的方式同时管理多个项目
    GIT 如何合并另一个远程Git仓库的文件到本地仓库里某个指定子文件夹并不丢失远程提交记录?
    如何导入另一个 Git库到现有的Git库并保留提交记录
    Total Commander如何设置自定义快捷键在当前目录打开ConEmu
    PHP ECSHOP中 诡异的问题:expects parameter 1 to be double
  • 原文地址:https://www.cnblogs.com/jsping/p/2532202.html
Copyright © 2011-2022 走看看