typedef struct {
ElementType Data;
int Parent;
}SetType;
//集合的运算
//查找某个元素所在的集合
int Find(SetType S[], ElementType X)
{
int i;
for (i = 0; i < MaxSize && S[i].Data != X; i++);
if (i >= Maxsize) return -1;
for (; S[i].Parent >= 0; i = S[i].Parent);
return i;
}
//集合的并运算
void Uniom(SetType s[], ElementType X1, ElementType X2)
{
int Root1, Root2;
Root1 = Find(S, X1);
Root2 = Find(S, X2);
if (Root1 != Root2) S[Root2].Parent = Root1;
}
集合及运算
最新推荐文章于 2024-08-07 19:21:33 发布