vendredi 29 mai 2020

How to find tha't circular list's begin?

I'm trying to implement about list and iterator of list like C++ STL.

The node in list is defined like this:

struct Node{
  Node *prev,*next;
  value_type data;
};

And I want to overloading operator > and < :

bool list_iterator::operator>(const iterator_impl_base &rhs) const
bool list_iterator::operator<(const iterator_impl_base &rhs) const

which means if I need to call next to reach rhs.node , it will return 0 in > and return 1 in <.

if I need to call prev to reach rhs.node , it return 1 in > and return 0 in <.

And I implement list using circular list. Below is one part of list class :

class List : public ordered_container {
 protected:
  Node* begin_;
  Node* end_;
  size_type size_;
 public:
    List::List() : end_(new Node){
        begin_ = end_->prev = end_->next = end_;
        size_=0;
    }
}

So , I don't know how to distinguish whether I just pass the begin_ of list. Can someone help me about that? Thankyou.

Aucun commentaire:

Enregistrer un commentaire