lemon/path.h
changeset 1207 eba5aa390aca
parent 1201 1f4f01870c1e
equal deleted inserted replaced
29:8f064d933553 30:bfa2c36ac8c8
   180     /// \pre \c n is in the <tt>[0..length() - 1]</tt> range.
   180     /// \pre \c n is in the <tt>[0..length() - 1]</tt> range.
   181     ArcIt nthIt(int n) const {
   181     ArcIt nthIt(int n) const {
   182       return ArcIt(*this, n);
   182       return ArcIt(*this, n);
   183     }
   183     }
   184 
   184 
       
   185     /// \brief The n-th arc.
       
   186     ///
       
   187     /// Gives back the n-th arc. This operator is just an alias for \ref nth(),
       
   188     /// it runs in O(1) time.
       
   189     /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
       
   190     const Arc& operator[](int n) const {
       
   191       return nth(n);
       
   192     }
       
   193 
   185     /// \brief The first arc of the path
   194     /// \brief The first arc of the path
   186     const Arc& front() const {
   195     const Arc& front() const {
   187       return head.empty() ? tail.front() : head.back();
   196       return head.empty() ? tail.front() : head.back();
   188     }
   197     }
   189 
   198 
   400     /// \brief  Initializes arc iterator to point to the n-th arc.
   409     /// \brief  Initializes arc iterator to point to the n-th arc.
   401     ArcIt nthIt(int n) const {
   410     ArcIt nthIt(int n) const {
   402       return ArcIt(*this, n);
   411       return ArcIt(*this, n);
   403     }
   412     }
   404 
   413 
       
   414     /// \brief The n-th arc.
       
   415     ///
       
   416     /// Gives back the n-th arc. This operator is just an alias for \ref nth(),
       
   417     /// it runs in O(1) time.
       
   418     /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
       
   419     const Arc& operator[](int n) const {
       
   420       return data[n];
       
   421     }
       
   422 
   405     /// \brief The first arc of the path.
   423     /// \brief The first arc of the path.
   406     const Arc& front() const {
   424     const Arc& front() const {
   407       return data.front();
   425       return data.front();
   408     }
   426     }
   409 
   427 
   614       Node *node = first;
   632       Node *node = first;
   615       for (int i = 0; i < n; ++i) {
   633       for (int i = 0; i < n; ++i) {
   616         node = node->next;
   634         node = node->next;
   617       }
   635       }
   618       return ArcIt(*this, node);
   636       return ArcIt(*this, node);
       
   637     }
       
   638 
       
   639     /// \brief The n-th arc.
       
   640     ///
       
   641     /// Looks for the n-th arc in O(n) time. This operator is just an alias
       
   642     /// for \ref nth().
       
   643     /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
       
   644     const Arc& operator[](int n) const {
       
   645       return nth(n);
   619     }
   646     }
   620 
   647 
   621     /// \brief Length of the path.
   648     /// \brief Length of the path.
   622     int length() const {
   649     int length() const {
   623       int len = 0;
   650       int len = 0;
   964     /// \brief The arc iterator pointing to the n-th arc.
   991     /// \brief The arc iterator pointing to the n-th arc.
   965     ArcIt nthIt(int n) const {
   992     ArcIt nthIt(int n) const {
   966       return ArcIt(*this, n);
   993       return ArcIt(*this, n);
   967     }
   994     }
   968 
   995 
       
   996     /// \brief The n-th arc.
       
   997     ///
       
   998     /// Gives back the n-th arc. This operator is just an alias for \ref nth(),
       
   999     /// it runs in O(1) time.
       
  1000     /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
       
  1001     const Arc& operator[](int n) const {
       
  1002       return _arcs[n];
       
  1003     }
       
  1004 
   969     /// \brief The length of the path.
  1005     /// \brief The length of the path.
   970     int length() const { return len; }
  1006     int length() const { return len; }
   971 
  1007 
   972     /// \brief Return true when the path is empty.
  1008     /// \brief Return true when the path is empty.
   973     int empty() const { return len == 0; }
  1009     int empty() const { return len == 0; }