• 线性表1


    1、线性表(LIST)的表现形式
    • 零个或者多个数据元素组成的集合
    • 数据元素在位置上是有序排列的
    • 数据元素的个数是有限
    • 数据元素的类型必须相同
     
    2、线性表的性质
    • a0为线性表的第一个元素,只有一个后继
    • an-1 为线性表的最后一个元素,只要一个前驱
    • 除a0和an-1 外的其他元素既有前驱又有后驱
    • 直接支持逐项访问和顺序存取
     
    3、线性表的一些常用操作
    • 创建线性表
    • 销毁线性表
    • 将元素插入线性表
    • 将元素从线性表中删除
    • 获取线性表中某个位置元素的值
    • 设置线性表中某个位置的元素的值
    • 获取线性表的长度
    • 清空线性表  
    4、线性表在程序中的表现:一种特殊的数据类型
         创建一个类(即一个新的数据类型)
    类模板
     1 template <typename T>
     2 class list: public Object
     3 {
     4 public:
     5     virtual bool insert(int i, const T& e)=0;
     6     virtual bool remove(int i)=0;
     7     virtual bool set(int i,const T& e)=0;
     8     virtual bool get(int i,T& e) const=0;
     9     virtual int length() const =0;
    10     virtual void clear()=0;
    11 }

     
     代码实现:
    由于是由类模板实现的所以就不需要cpp文件
     
    List.h
     
     1 #ifndef LIST_H
     2 #define LIST_H
     3 #include"object.h"
     4  5 namespace DTLib
     6 {
     7 template <typename T>
     8  9 class List: public Object
    10 {
    11 public:
    12     virtual bool insert(int i, const T& e)=0;
    13     virtual bool remove(int i)=0;
    14     virtual bool set(int i,const T& e)=0;
    15     virtual bool get(int i,T& e) const=0;
    16     virtual int length() const =0;
    17     virtual void clear()=0;
    18 };
    19 }
    20 #endif // LIST_H
     
     
    List仅仅是一个抽象类,用来被继承
     
    main.cpp 
     
    #include <iostream>
    #include "list.h"using namespace std;
    using namespace DTLib;
    ​
    ​
    int main(int argc, char *argv[])
    {
      List<int>* l=NULL;
      return 0;
    }
    ​
     
     
    5、小结
    • 线性表是数据元素的有序并且有限的集合
    • 线性表中的数据元素必须是类型相同的
    • 线性表可用于描述排队关系的问题
    • 线性表在程序中表现为一种特殊的数据类型
    • 线性表在C++中表现为一个抽象类  
     
  • 相关阅读:
    大话设计模式——UML图
    IdentityServer3零星笔记
    Angular路由
    基于jquery的静态页面翻页
    00_python安装与配置(mac)
    OracleParameter.UdtTypeName的值必须是全大写!
    VS2012调用64位IIS Express
    MVC中使用Ueditor
    优秀博客站点
    jqGrid中的formatter
  • 原文地址:https://www.cnblogs.com/zhaobinyouth/p/9563898.html
Copyright © 2020-2023  润新知