数据结构第六章第五节.pptVIP

  • 3
  • 0
  • 约2.32万字
  • 约 89页
  • 2017-05-30 发布于四川
  • 举报
并查集的树表示 -7 0 0 2 2 2 4 4 7 7 A B C D E F G H i j 0 1 2 3 4 5 6 7 8 9 int collapsefind_mfset(MFSet S, TElemType x){ //找集合S中元素x所在子集的根的位置,同时进行路径压缩 j=Locate(S, x); //确定x所在的位置,如果不存在,返回-1; if(j==-1) return –1; //元素x不属于任一子集 for(i=j; S.nodes[i].parent 0; i=S.nodes[i].parent; while(i!=S.nodes[j].parent){ k=S.nodes[j].parent; sets[j].parent=i; j=k; } return i; }//collapsefind_mfset i=0 j=7 A B C D E F G H j i k 0 k=4 并查集的树表示 -7 0 0 2 2 2 4 4 7 7 A B C D E F G H i j 0 1 2 3 4 5 6 7 8 9 int collapsefind_mfset(MFSet S, TElemType x){ //找集合S中元素x所在子集的根的位置,同时进

文档评论(0)

1亿VIP精品文档

相关文档