weightededge.h

来自「《数据结构、算法与应用》从C++语言应用角度列举了要点」· C头文件 代码 · 共 39 行

H
39
字号

// edge in a weighted graph

#ifndef weightedEdge_
#define weightedEdge_

#include "edge.h"

using namespace std;

template <class T>
class weightedEdge : public edge<T>
{
   public:
      weightedEdge() {};
      weightedEdge(int theV1, int theV2, T theW)
         {v1 = theV1; v2 = theV2; w = theW;}
      ~weightedEdge() {};
      int vertex1() const {return v1;}
      int vertex2() const {return v2;}
      T weight() const {return w;}
      operator T() const {return w;}
      void output(ostream& out) const
      {// Put the edge into the stream out.
         out << "(" << v1 << ", " << v2 << ", " << w << ")";
      }

   private:
      int v1,
          v2;
      T w;
};

// overload <<
template <class T>
ostream& operator<<(ostream& out, const weightedEdge<T>& x)
   {x.output(out); return out;}
#endif

⌨️ 快捷键说明

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