正在加载图片...
第8章图 ); int Find( int x ) rivate at m sIze: class Graph enum Max VerticesNum=50: Graph( int Vertices=0) Current Vertices= Vertices; InitGraph0; 3 void Kruskal O int Get Vertices(i return Current Vertices; 3 private: int Current Vertices } class GraphEdge i t head, tail int cost; int operator <= GraphEdge &ed ) GraphEdge operator <= GraphEdge &ed)i return this ->cost <=ed cos UFSets: UFSets( int MaxSize )i m sIze MaxSize m pArent=new int[m sIze]: for( int i=0; i <m_ sIze; i++)m pArent[=1; void UFSets: Union( int Rootl, int Root)i t2]= root; int UFSets: Find( int x)1 while(m nt(]>=0)x=m_pArent(x]:第 8 章 图 102 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; } int UFSets :: Find ( int x ) { while ( m_pParent[x] >= 0 ) x = m_pParent[x]; return x;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有