Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7565119
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: C/C++

2011-04-03 14:29:00

  1. /******************************************************************************
  2. * 文件:LinearList.h
  3. * 功能:线性表抽象类
  4. * 说明:将线性表视为一个抽象对象/类(亦称接口),
  5.         即不考虑它的具体数据结构存储,不考虑基本操作的实现,
  6.         只考虑它的基本操作接口(输入/输出)
  7. * 时间:2011-4-3                                              
  8. Author: Lzy
  9. *******************************************************************************/
  10. #include <iostream.h>

  11. /********************************************************************
  12. * 类名: 类模板LinearList
  13. * 功能: 线性表抽象类
  14. * 说明:
  15. ********************************************************************/
  16. template<class T>
  17. class LinearList
  18. {
  19. public:
  20. //    LinearList();                                        //构造函数

  21. //    virtual ~LinearList() ;                            //纯虚析构函数

  22.     virtual bool IsEmpty() const {return length ==0;}    //检查表是否为空

  23.     virtual int Length() const {return length;}            //返回表有多长

  24.     virtual bool Find(int k, T &x) const = 0;            //返回第K个元素到x中,在具体类中完成

  25.     virtual bool Delete(int k, T &x) = 0;                //删除第K个元素并将它返回至x

  26.     virtual bool Insert(int k, const T &x) = 0;            //在第K个元素之后插入x

  27.     virtual void Output(ostream &out) const = 0;        //输出    

  28.     
  29. protected:
  30.     long length;    
  31. };

  32. /***************异常类*****************/
  33. //内存空间不足

  34. class NoMem
  35. {
  36. public:
  37.     NoMem(){cout<<endl<<"Insufficient memory!!"<<endl;}
  38. };

  39. //越界

  40. class OutOfBounds
  41. {
  42. public:
  43.     OutOfBounds(){cout<<endl<<"Beyond the scope!!"<<endl;}
  44. };
阅读(1990) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~