📄 disjsetsanimation.java
字号:
import java.io.DataInputStream;import edu.odu.cs.zeil.AlgAE.Server.Animation;import edu.odu.cs.zeil.AlgAE.Server.MenuFunction;import edu.odu.cs.zeil.AlgAE.Server.Visible;import edu.odu.cs.zeil.AlgAE.Server.VisibleRendering;import edu.odu.cs.zeil.AlgAE.Server.algae;import DisjSets;/** * Driver for demo of disjoint set union/find algorithms from * Weiss' Algorithms, Data Structures and Problem Solving with Java * * This driver can be executed either as an applet or as a standalone * application. * * @author Steven J. Zeil **/public class DisjSetsAnimation extends Animation{ private DisjSets theSet; /** * Constructor for applets */ public DisjSetsAnimation () { super ("Disjoint Sets"); theSet = null; } /** * Constructor for standalone applications */ public DisjSetsAnimation (String[] args) { super ("Disjoint Sets", args); theSet = null; } /** * Documentation string for Help..About box. */ public String about() { return "Disjoint set code from\n" + " Mark Allen Weiss: Data Structures and Problem Solving Using Java\n" + " 1998, Addison Wesley\n\n" + "converted to AlgAE demo by\n" + " Steven Zeil, Old Dominion Univ."; } /** * Algorithm menu items */ public void menu () { algae.menuItem ("generate disjoint set", new MenuFunction () { public void selected() { boolean done = false; int N = 0; while (!done) { String response = algae.promptForInput ("How large a set?"); try { N = new Integer(response).intValue(); done = true; } catch (NumberFormatException e) {} } theSet = new DisjSets (N); } }); algae.menuItem ("union", new MenuFunction () { public void selected() { if (theSet == null) theSet = new DisjSets (12); boolean done = false; int A = 0; int B = 0; while (!done) { String response = algae.promptForInput ( "First set for union?"); try { A = new Integer(response).intValue(); done = true; } catch (NumberFormatException e) {} } done = false; while (!done) { String response = algae.promptForInput ( "Second set for union?"); try { B = new Integer(response).intValue(); done = true; } catch (NumberFormatException e) {} } theSet.union (A, B); } }); algae.menuItem ("find", new MenuFunction () { public void selected() { if (theSet == null) theSet = new DisjSets (12); boolean done = false; int A = 0; while (!done) { String response = algae.promptForInput ( "Value to find?"); try { A = new Integer(response).intValue(); done = true; } catch (NumberFormatException e) {} } int B = theSet.find (A); algae.out().println ("find(" + A + ") == " + B); } }); } public static void main(String[] args) { DisjSetsAnimation demo = new DisjSetsAnimation(args); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -