title: Iterator on double Linkedlist class
body: <p>This code is from a "Data Structures" book By Micheal T.Goodrigh. I'm studying on my own so I have no one to explain this code for me:</p>
  
  <pre><code>typedef int Elem;               // list base element type
  class NodeList {              // node-based list
  private:
    struct Node {               // a node of the list
      Elem elem;                // element value
      Node* prev;               // previous in list
      Node* next;               // next in list
    };
  public:
    class Iterator {                // an iterator for the list
    public:
      Elem&amp; operator*();            // reference to the element
      bool operator==(const Iterator&amp; p) const; // compare positions
      bool operator!=(const Iterator&amp; p) const;
      Iterator&amp; operator++();           // move to next position
      Iterator&amp; operator--();           // move to previous position
      friend class NodeList;            // give NodeList access
    private:
      Node* v;                  // pointer to the node
      Iterator(Node* u);            // create from node
    };
  public:
    NodeList();                 // default constructor
    int size() const;               // list size
    bool empty() const;             // is the list empty?
    Iterator begin() const;         // beginning position
    Iterator end() const;           // (just beyond) last position
    void insertFront(const Elem&amp; e);        // insert at front
    void insertBack(const Elem&amp; e);     // insert at rear
    void insert(const Iterator&amp; p, const Elem&amp; e); // insert e before p
    void eraseFront();              // remove first
    void eraseBack();               // remove last
    void erase(const Iterator&amp; p);      // remove p
  private:                  // data members
    int     n;                  // number of items
    Node*   header;             // head-of-list sentinel
    Node*   trailer;                // tail-of-list sentinel
  };
  </code></pre>
  
  <p>I'm very confused how I use the <code>insert()</code> method.  How do I pass an iterator to it while the iteretor is inside its class and <code>Node</code> is private?</p>
  
  <pre><code>int main () {
    NodeList Nl;
    N1.insert(p,5)      // How to create this p iterator and pass it to insert?
    return 0; 
  }
  </code></pre>