📄 persongroup.jad
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2005-12-1 23:29:14
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: ShellSort.java
import java.awt.Color;
import java.awt.Graphics;
class personGroup
{
public personGroup(int i, int j)
{
aSize = i;
initOrder = j;
theArray = new person[aSize + 2];
if(aSize == 100)
{
barWidth = 2;
barSeparation = 1;
} else
{
barWidth = 18;
barSeparation = 7;
}
for(h = 1; h <= aSize / 3; h = h * 3 + 1);
Inner = Outer = h;
innerOld = outerOld = h;
comps = 0;
copies = 0;
doneFlag = false;
note = "Press any button";
codePart = 1;
Color color = new Color(0, 0, 0);
if(initOrder == 1)
{
for(int k = 0; k < aSize; k++)
{
int i1 = 20 + (int)(Math.random() * 175D);
int k1 = (int)(Math.random() * 254D);
int i2 = (int)(Math.random() * 254D);
int k2 = (int)(Math.random() * 254D);
color = new Color(k1, i2, k2);
theArray[k] = new person(i1, color);
}
} else
{
for(int l = 0; l < aSize; l++)
{
int j1 = 195 - (175 * l) / aSize;
int l1 = 255 - j1;
int j2 = 85 * (l % 3);
int l2 = j1;
color = new Color(l1, j2, l2);
theArray[l] = new person(j1, color);
}
}
theArray[aSize + 1] = new person(0, color);
drawMode = 2;
}
public void setDrawMode(int i)
{
drawMode = i;
}
public int getAppletWidth()
{
return 370;
}
public int getAppletHeight()
{
return 320;
}
public boolean getDone()
{
return doneFlag;
}
public void arrowText(Graphics g, Color color, String s, int i, int j, boolean flag, boolean flag1)
{
int k = 35 + i * (barWidth + barSeparation);
int l = 230 + (j + 1) * 13;
g.setColor(color);
if(flag1)
g.drawString(s, k, l);
if(flag)
{
g.drawLine(k + barWidth / 2, 232, k + barWidth / 2, l - 13);
g.drawLine(k + barWidth / 2, 232, (k + barWidth / 2) - 3, 237);
g.drawLine(k + barWidth / 2, 232, k + barWidth / 2 + 3, 237);
}
}
public void drawOneBar(Graphics g, int i)
{
if(theArray[i] == null)
{
int j = 35 + i * (barWidth + barSeparation);
g.setColor(Color.lightGray);
g.fillRect(j, 30, barWidth, 200);
return;
}
if(i < 0 || i > aSize + 1)
return;
int k = theArray[i].getHeight();
if(k < 5)
{
return;
} else
{
int l = 35 + i * (barWidth + barSeparation);
int i1 = 230 - k;
Color color = theArray[i].getColor();
g.setColor(Color.lightGray);
g.fillRect(l, 30, barWidth, 200);
g.setColor(color);
g.fill3DRect(l, i1, barWidth, k, true);
return;
}
}
public void draw(Graphics g)
{
if(drawMode != 2)
{
switch(codePart)
{
case 3: // '\003'
case 6: // '\006'
drawOneBar(g, aSize + 1);
drawOneBar(g, innerOld);
drawOneBar(g, Inner);
break;
case 2: // '\002'
case 5: // '\005'
drawOneBar(g, innerOld);
drawOneBar(g, Inner);
drawOneBar(g, aSize + 1);
break;
}
} else
{
g.setColor(Color.lightGray);
g.fillRect(0, 0, 370, 320);
for(int i = 0; i < aSize; i++)
drawOneBar(g, i);
drawOneBar(g, aSize + 1);
arrowText(g, Color.magenta, "xxx", aSize + 1, 3, true, false);
}
g.setColor(Color.lightGray);
g.fillRect(0, 0, 120, 32);
g.setColor(Color.black);
g.drawString("Comparisons = " + comps, 10, 28);
g.drawString("Copies = " + copies, 10, 15);
g.setColor(Color.lightGray);
g.fillRect(0, 230, 370, 78);
arrowText(g, Color.black, "h=" + h, 8, 5, false, true);
if(aSize == 10)
{
arrowText(g, Color.red, "outer", Outer, 1, true, true);
arrowText(g, Color.blue, "inner", Inner, 2, true, true);
if(Inner - h >= 0)
arrowText(g, Color.blue, "inner-h", Inner - h, 3, true, true);
arrowText(g, Color.magenta, "temp", aSize + 1, 1, true, true);
arrowText(g, Color.black, note, 0, 4, false, true);
} else
{
arrowText(g, Color.red, "xxx", Outer, 1, true, false);
arrowText(g, Color.blue, "xxx", Inner, 2, true, false);
arrowText(g, Color.blue, "xxx", Inner - h, 2, true, false);
}
drawMode = 2;
}
public void sortStep()
{
if(doneFlag)
return;
switch(codePart)
{
case 1: // '\001'
note = h + "-sorting array; will copy outer to temp";
codePart = 2;
return;
case 2: // '\002'
copies++;
theArray[aSize + 1] = theArray[Outer];
theArray[Outer] = null;
innerOld = Inner;
Inner = Outer;
if(Inner > h - 1)
note = "Will compare inner-h and temp";
else
note = "There is no inner-h";
codePart = 3;
return;
case 3: // '\003'
if(Inner > h - 1)
{
comps++;
if(theArray[Inner - h].getHeight() >= theArray[aSize + 1].getHeight())
{
note = "inner-h >= temp; will copy inner-h to inner";
codePart = 4;
return;
} else
{
note = "inner-h < temp; will copy temp to inner";
codePart = 5;
return;
}
} else
{
note = "Will copy temp to inner";
codePart = 5;
return;
}
case 4: // '\004'
theArray[Inner] = theArray[Inner - h];
theArray[Inner - h] = null;
copies++;
innerOld = Inner;
Inner -= h;
if(Inner > h - 1)
note = "Will compare inner-h and temp";
else
note = "There is no inner-h";
codePart = 3;
return;
case 5: // '\005'
theArray[Inner] = theArray[aSize + 1];
theArray[aSize + 1] = null;
copies++;
outerOld = Outer;
Outer++;
if(Outer < aSize)
{
note = "Will copy outer to temp";
codePart = 2;
return;
}
h = (h - 1) / 3;
if(h > 0)
{
Inner = Outer = h;
note = h + "-sorting array. Will copy outer to temp";
codePart = 2;
return;
} else
{
note = "Sort is complete";
codePart = 6;
return;
}
case 6: // '\006'
doneFlag = true;
note = "Sort is complete";
codePart = 6;
return;
}
}
private final int appletWidth = 370;
private final int appletHeight = 320;
private final int maxHeight = 200;
private final int topMargin = 30;
private final int leftMargin = 10;
private final int barLeftMargin = 35;
private final int textHeight = 13;
private int aSize;
private person theArray[];
private int barWidth;
private int barSeparation;
private int Outer;
private int Inner;
private int outerOld;
private int innerOld;
private int h;
private boolean doneFlag;
private int codePart;
private int comps;
private int copies;
private int initOrder;
private String note;
private int drawMode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -