import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.lang.InterruptedException;
publicclassAlgoVisHelper {privateAlgoVisHelper(){}
publicstaticfinal Color Red = new Color(0xF44336);
publicstaticfinal Color Pink = new Color(0xE91E63);
publicstaticfinal Color Purple = new Color(0x9C27B0);
publicstaticfinal Color DeepPurple = new Color(0x673AB7);
publicstaticfinal Color Indigo = new Color(0x3F51B5);
publicstaticfinal Color Blue = new Color(0x2196F3);
publicstaticfinal Color LightBlue = new Color(0x03A9F4);
publicstaticfinal Color Cyan = new Color(0x00BCD4);
publicstaticfinal Color Teal = new Color(0x009688);
publicstaticfinal Color Green = new Color(0x4CAF50);
publicstaticfinal Color LightGreen = new Color(0x8BC34A);
publicstaticfinal Color Lime = new Color(0xCDDC39);
publicstaticfinal Color Yellow = new Color(0xFFEB3B);
publicstaticfinal Color Amber = new Color(0xFFC107);
publicstaticfinal Color Orange = new Color(0xFF9800);
publicstaticfinal Color DeepOrange = new Color(0xFF5722);
publicstaticfinal Color Brown = new Color(0x795548);
publicstaticfinal Color Grey = new Color(0x9E9E9E);
publicstaticfinal Color BlueGrey = new Color(0x607D8B);
publicstaticfinal Color Black = new Color(0x000000);
publicstaticfinal Color White = new Color(0xFFFFFF);
publicstaticvoidstrokeCircle(Graphics2D g, int x, int y, int r){
Ellipse2D circle = new Ellipse2D.Double(x-r, y-r, 2*r, 2*r);
g.draw(circle);
}
publicstaticvoidfillCircle(Graphics2D g, int x, int y, int r){
Ellipse2D circle = new Ellipse2D.Double(x-r, y-r, 2*r, 2*r);
g.fill(circle);
}
publicstaticvoidstrokeRectangle(Graphics2D g, int x, int y, int w, int h){
Rectangle2D rectangle = new Rectangle2D.Double(x, y, w, h);
g.draw(rectangle);
}
publicstaticvoidfillRectangle(Graphics2D g, int x, int y, int w, int h){
Rectangle2D rectangle = new Rectangle2D.Double(x, y, w, h);
g.fill(rectangle);
}
publicstaticvoidsetColor(Graphics2D g, Color color){
g.setColor(color);
}
publicstaticvoidsetStrokeWidth(Graphics2D g, int w){
int strokeWidth = w;
g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
}
publicstaticvoidpause(int t) {
try {
Thread.sleep(t);
}
catch (InterruptedException e) {
System.out.println("Error sleeping");
}
}
}
数据层
publicclass SelectionSortData {
privateint[] numbers;
publicint orderedIndex = -1; // [0...orderedIndex) 是有序的publicint currentCompareIndex = -1; // 当前正在比较的元素索引publicint currentMinIndex = -1; // 当前找到的最小元素的索引publicSelectionSortData(int N, int randomBound){
numbers = newint[N];
//准备数据for( int i = 0 ; i < N ; i ++)
numbers[i] = (int)(Math.random()*randomBound) + 1;
}
publicintN(){
return numbers.length;
}
publicintget(int index){
if( index < 0 || index >= numbers.length)
thrownew IllegalArgumentException("Invalid index to access Sort Data.");
return numbers[index];
}
publicvoidswap(int i, int j) {
if( i < 0 || i >= numbers.length || j < 0 || j >= numbers.length)
thrownew IllegalArgumentException("Invalid index to access Sort Data.");
int t = numbers[i];
numbers[i] = numbers[j];
numbers[j] = t;
}
}