2012-06-22 21 views

回答

2
Mark all nodes unassigned. 

Iterate through all nodes: 
    If node unassigned: 
     Assign node to a new component id C 
     Do a depth-first-search for all nodes connected to this one: 
      mark them with same component id C 
+0

非常感谢您的回复。我应该使用数组来初始标记所有节点吗? – SRINI794

+1

是的。创建一个与矩阵大小相同的int数组。 0初始化意味着未分配。从1开始计数组件。 –

+0

非常感谢:)如您所说,我会解决问题。我们很快会在此更新。 – SRINI794

1

,利用工会找到的数据结构(也称为不相交集数据strucutre)