栈  0.1
数据结构_第3章
List.h
Go to the documentation of this file.
1 
12 #ifndef __ListIncluded
13 #define __ListIncluded
14 
15 namespace List
16 {
17 // 线性表的抽象类
18 template <typename T>
19 class List
20 {
21 public:
23  {
24  public:
25  virtual const T &operator*() const = 0;
26  virtual const_iterator &operator++() = 0;
27  // 不能返回抽象类,只能返回抽象类的指针或引用
28  // virtual const_iterator operator++(int) = 0;
29  virtual bool operator==(const const_iterator &rhs) const = 0;
30  virtual bool operator!=(const const_iterator &rhs) const = 0;
31  };
32 
33  class iterator : public const_iterator
34  {
35  public:
36  virtual T &operator*() = 0;
37  virtual const T &operator*() const = 0;
38  virtual iterator &operator++() = 0;
39  // 不允许返回抽象类,只能返回抽象类的指针或引用
40  // virtual iterator operator++(int) = 0;
41  virtual bool operator==(const iterator &rhs) const = 0;
42  virtual bool operator!=(const iterator &rhs) const = 0;
43  };
44 
45 public:
46  virtual void clear() = 0; // 删除线性表中所有的元素
47  virtual int length() const = 0; // 返回线性表的长度
48  virtual void insert(int i, const T &obj) = 0; // 在第i个位置插入一个元素,即新元素的下标将为i
49  virtual void remove(int i) = 0; // 删除第i个位置的元素
50  virtual int search(const T &obj) const = 0; // 返回元素obj在线性表中首次出现的下标
51  virtual T visit(int i) const = 0; // 返回线性表中第i个元素
52  // virtual void traverse() const = 0; // 遍历线性表
53  virtual ~List() = default; // 虚析构函数,防止内存泄漏
54 
55  // 不允许返回抽象类,只能返回抽象类的指针或引用
56  // virtual iterator begin() = 0; // 数据范围[begin, end)
57  // virtual const_iterator begin() const = 0;
58  // virtual iterator end() = 0;
59  // virtual const_iterator end() const = 0;
60 };
61 } // namespace List
62 
63 #include "dLinkList.h" // 双链表类的实现
64 #include "sLinkList.h" // 单链表类的实现
65 #include "seqList.h" // 顺序表类的实现
66 
67 #endif
dLinkList.h
双链表类
sLinkList.h
单链表类的定义和实现
List
Definition: dLinkList.h:19
RPN::operator==
bool operator==(const Rpn_t::Item &lhs, const Rpn_t::Item &rhs)
Definition: Rpn.hh:740
seqList.h
顺序表类
List::List::iterator
Definition: List.h:33
List::List::const_iterator
Definition: List.h:22