unionfindsettests.java
来自「<算法导论>第二版大部分算法实现. 1. 各类排序和顺序统计学相关」· Java 代码 · 共 42 行
JAVA
42 行
/* * Copyright (C) 2003-2008 Wang Pengcheng <wpc0000@gmail.com> * Permission is granted to copy, distribute and/or modify this * document under the terms of the GNU Free Documentation License, * Version 2.0 or any later version published by the Free Software Foundation; * with no Invariant Sections. * You may obtain a copy of the License at * http://www.gnu.org/licenses/lgpl.txt *///9 Apr 2008package cn.edu.whu.iss.algorithm.unit21.test;import cn.edu.whu.iss.algorithm.unit21.UnionFind;import cn.edu.whu.iss.algorithm.unit21.UnionFindSet;import junit.framework.TestCase;import mypackage.tools.print.*;public class UnionFindSetTests extends TestCase { protected void setUp() throws Exception { super.setUp(); } public void testUnion() { int a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10; UnionFind<Integer> set = new UnionFindSet<Integer>(); set.add(a);set.add(b);set.add(c);set.add(d);set.add(e); set.add(f);set.add(g);set.add(h);set.add(i);set.add(j); set.union(b, d); set.union(e, g); set.union(a, c); set.union(h, i); set.union(a, b); set.union(e, f); set.union(b, c); P.rintln(set.getItemsInSetOf(a)); P.rintln(set.getItemsInSetOf(e)); P.rintln(set.getItemsInSetOf(h)); P.rintln(set.getItemsInSetOf(j)); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?