MP3
Linked Lists
List-ListIterator.hpp
1 
2 class ListIterator : public std::iterator<std::bidirectional_iterator_tag, T> {
3  private:
4  ListNode* position_;
5 
6  public:
7  ListIterator() : position_(nullptr) { }
8  ListIterator(ListNode* x) : position_(x) { }
9 
10  // Pre-Increment, ++iter
11  ListIterator& operator++() {
12  // @TODO: graded in MP3.1
13  return *this;
14  }
15 
16  // Post-Increment, iter++
17  ListIterator operator++(int) {
18  ListNode* temp = position_;
19  position_ = position_->next;
20  return ListIterator(temp);
21  }
22 
23  // Pre-Decrement, --iter
24  ListIterator& operator--() {
25  position_ = position_->prev;
26  return *this;
27  }
28 
29  // Post-Decrement, iter--
30  ListIterator operator--(int) {
31  // @TODO: graded in MP3.1
32  return ListIterator();
33  }
34 
35  bool operator==(const ListIterator& rhs) {
36  return !(*this != rhs);
37  }
38 
39  bool operator!=(const ListIterator& rhs) {
40  // @TODO: graded in MP3.1
41  return false;
42  }
43 
44  const T& operator*() {
45  return position_->data;
46  }
47 
48  const T* operator->() {
49  return &(position_->data);
50  }
51 };
Definition: List-ListIterator.hpp:2