正在加载图片...
第8章图 i MaxUnionSize =503; lionIze ) FSetso delete []m pArent; 3 void Union( int Rootl, int Root ) int Find( int x ) r at m sIze: 中 m pArent 50}; Graph( int Vertices=0)( Current Vertices = Vertices; InitGraph0: 1 void InitGraph 0; int Get Vertices(i return Current Vertices; 3 private int Current Vertices class GraphEdge i head, tail &ed); GraphEdge : operator <= GraphEdge &ed)i return this ->cost <=ed cos UFSets: UFSets( int MaxSize)i m_pArent=new int[m sIze] void UFSets: Union( int Rootl, int Root2 )t第 8 章 图 102 enum { MaxUnionSize = 50 }; UFSets ( int MaxSize = MaxUnionSize ); ~UFSets () { delete [ ] m_pParent; } void Union ( int Root1, int Root2 ); int Find ( int x ); private: int m_iSize; int *m_pParent; }; class Graph { public: enum { MaxVerticesNum = 50 }; Graph( int Vertices = 0) { CurrentVertices = Vertices; InitGraph(); } void InitGraph (); void Kruskal (); int GetVerticesNum () { return CurrentVertices; } private: int Edge[MaxVerticesNum][MaxVerticesNum]; int CurrentVertices; }; class GraphEdge { public: int head, tail; int cost; int operator <= ( GraphEdge &ed ); }; GraphEdge :: operator <= ( GraphEdge &ed ) { return this->cost <= ed.cost; } UFSets :: UFSets ( int MaxSize ) { m_iSize = MaxSize; m_pParent = new int[m_iSize]; for ( int i = 0; i < m_iSize; i++ ) m_pParent[i] = -1; } void UFSets :: Union ( int Root1, int Root2 ) { m_pParent[Root2] = Root1; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有