正在加载图片...
B Code of Union-by-height (rank) /Assume Root and Root are Roots Union is a C ketword, so this routine is named setUnion void SetUnion (DisjSet s, SetType Root1, SetType root2) if(s[Root2≤s[Root1) /Root2 is deeperset s[Root1]=Root2; //make Root2 new root else if(s[Root1]=s[Root2] /same height s[Root1]--; / so update s[Root2Root1;/*Assume Root1 and Root2 are Roots Union is a C ketword, so this routine is named SetUnion */ void SetUnion(DisjSet s,SetType Root1, SetType Root2) { if(s[Root2]<s[Root1]) //Root2 is deeper set s[Root1]=Root2; //make Root2 new root else { if(s[Root1]==s[Root2]) //same height s[Root1]--; //so update s[Root2]=Root1; } } ❖ Code of Union-by-height (rank)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有