正在加载图片...
Im plementation 2: s[element]=the elements parent. Note: S[ root]=0 and set name= root index. I Example The array representation of the three sets is Heave use中2图4ospo Hence they can be ual a of an ard void SetUnion( DisjSet S, (S1∪S SetType Rt1 SetType Rt2) I s[Rt2 ]=Rt1; y ☆Find(i) Im plementation 1: Implementation 2: SetType Find( elementType X, name啊ks DisjSet S) I for(; S[X]>0; X=SX]); return X; find(i)='sHere we use the fact that the elements are numbered from 1 to N. Hence they can be used as indices of an array. Implementation 2: S [ element ] = the element’s parent. Note: S [ root ] = 0 and set name = root index. 10 6 7 8 4 1 9 2 3 5 〖Example〗The array representation of the three sets is ( S1  S2  S1 )  S [ 4 ] = 10 ❖ Find ( i ) Implementation 1: name[k] S • j i ... find ( i ) = ‘S’ Implementation 2: SetType Find ( ElementType X, DisjSet S ) { for ( ; S[X] > 0; X = S[X] ) ; return X ; } void SetUnion ( DisjSet S, SetType Rt1, SetType Rt2 ) { S [ Rt2 ] = Rt1 ; } [1] 4 [2] 0 [10] 0 [9] 4 [8] 10 [7] 10 [6] 10 [5] 2 [4] 0 [3] 2 S 10
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有