lwg.h

来自「一本全面剖析C++数据结构算法的书籍」· C头文件 代码 · 共 65 行

H
65
字号
// file lwg.h// linked weighted graphs// final version#ifndef LinkedWGraph_#define LinkedWGraph_#include "lwdg.h"#include "undirect.h"#include "unetwork.h"#include "xcept.h"template<class T>class LinkedWGraph : public LinkedWDigraph<T>,                     virtual public Undirected,		     virtual public UNetwork<T> {   public:      LinkedWGraph(int Vertices = 10)        : LinkedWDigraph<T> (Vertices) {}      LinkedWGraph<T>& Add(int i, int j, const T& w);      LinkedWGraph<T>& Delete(int i, int j);      int Degree(int i) const {return InDegree(i);}      int OutDegree(int i) const {return InDegree(i);}   protected:      LinkedWGraph<T>& AddNoCheck(int i, int j, const T& w);};template<class T>LinkedWGraph<T>& LinkedWGraph<T>           ::Add(int i, int j, const T& w){// Add edge (i,j).   if (i < 1 || j < 1 || i > n || j > n || i == j       || Exist(i, j)) throw BadInput();   return AddNoCheck(i, j, w);}template<class T>LinkedWGraph<T>& LinkedWGraph<T>          ::AddNoCheck(int i, int j, const T& w){// Add edge (i,j).   GraphNode<T> x;   x.vertex = j; x.weight = w;   h[i].Insert(0,x); // put on i's list   x.vertex = i;   try {h[j].Insert(0,x);}   catch (...) // insert failed      {// undo previous insert       x.vertex = j; h[i].Delete(x);       throw;} // throw same exception   e++;   return *this;}template<class T>LinkedWGraph<T>& LinkedWGraph<T>                 ::Delete(int i, int j){// Delete edge (i,j).   LinkedWDigraph<T>::Delete(i,j);   LinkedWDigraph<T>::Delete(j,i);   e++; // compensate   return *this;}#endif

⌨️ 快捷键说明

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