原题:扩展迭代器类arrayList::iterator(程序5-11),使得它成为随机访问迭代器。利用STL的排序函数对一个线性表排序,以测试这个迭代器类。
以下代码为加入到arrayList.h头文件中iterator类的定义:
// iterators to start and end of list
class iterator;
iterator begin() {return iterator(element);}
iterator end() {return iterator(element + listSize);}
// iterator for arrayList
class iterator
{
public:
// typedefs required by C++ for a bidirectional iterator
typedef bidirectional_iterator_tag iterator_category;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef T& reference;
// constructor
iterator(T* thePosition = 0) {position = thePosition;}
// dereferencing operators
T& operator*() const {return *position;}
T* operator->() const {return &*position;}
// increment
iterator& operator++()