lwgiter.h

来自「数据结构c++语言描述 Borland C++实现」· C头文件 代码 · 共 37 行

H
37
字号

// iterator for linked weighted graphs

#ifndef LinkedWeightedIterator_
#define LinkedWeightedIterator_

#include "lwdgph2.h"
#include "gnode.h"
#include "citer.h"

template <class T>
class LinkedWeightedIterator {
   public:
      int Begin(LinkedWDigraph<T>& G, int i);
      int NextVertex();
   private:
      ChainIterator<GraphNode<T> > p;  // used to traverse adjacency list
};

template <class T>
int LinkedWeightedIterator<T>::
    Begin(LinkedWDigraph<T>& G, int i)
{// Return first vertex adjacent to vertex i.
   if (i < 1 || i > G.n) throw OutOfBounds();
   GraphNode<T> *x = p.Initialize(G.h[i]);
   return (x) ? x->vertex : 0;
}

template <class T>
int LinkedWeightedIterator<T>::NextVertex()
{// Return next adjacent vertex.
   GraphNode<T> *x = p.Next();
   return (x) ? x->vertex : 0;
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?