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;

          }

        }

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

      }

  • 相关阅读:
    ReactiveCocoa -函数式编程和响应式编程
    关于即时通讯功能开发技术选型
    cordova 打包的项目里加入微信支付功能编译问题。
    OC和swift互相调用。
    有关 -all_load和-ObjC
    在一个项目中同时使用Swift和Objective-C代码混合编程的方法
    iOS开发中Static和Const关键字的的作用
    开发所有插件必须要这个插件
    phonegap 二维码扫描插件使用
    大数据基础---Kafka深入理解分区副本机制
  • 原文地址:https://www.cnblogs.com/jsping/p/2532202.html
Copyright © 2011-2022 走看看