⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shellpersongroup.java

📁 本软件是使用java 开发的
💻 JAVA
字号:
package datastructure;import java.awt.*;class ShellPersonGroup {  public ShellPersonGroup(int [] data, CodeAnimationPanel codePanel) {    this.codePanel = codePanel; theArray = new person[data.length];    barWidth = 20;    barSeparation = 10;    doneFlag = false;   // note = ""; codePart = 1;  drawMode = 2;  for (int k =1; k <data.length; k++) {   int i1 =data[k];   int k1 = (int) (Math.random() * 254);   int i2 = (int) (Math.random() * 254);   int k2 = (int) (Math.random() * 254);   color = new Color(k1, i2, k2);   theArray[k] = new person(i1, color);    }  }  public void setDrawMode(int i) {    drawMode = i;  }  public int getAppletWidth() {    return 450;  }  public int getAppletHeight() {    return 380;  }  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(oldcodePart)               {               case 6:                   drawOneBar(g, aSize + 1);                   drawOneBar(g,countsize);                  // drawOneBar(g, Inner);                   break;               //case 2:   //                 case 8:     // '\005'                   drawOneBar(g, j);                   drawOneBar(g, j+h);                   //drawOneBar(g, aSize + 1);                   break;                case 9:                  drawOneBar(g,aSize+1);                  drawOneBar(g,j+h);               }           } else        {*/    g.setColor(Color.lightGray);    g.fillRect(0, 0, 370, 320);    for (int i = 1; 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);      }           //drawMode = 2;*/  }  public void sortStep() { //稀而的算法实现    if (doneFlag) { //做完      return;    }    switch (codePart) {      case 1:        codePanel.highlight(1);        codePart = 2;        return;      case 2: // '\001'        if (count > 0) {          codePart = 3;        }        else {          codePart = 11;        }        codePanel.highlight(2);        return;      case 3:        codePanel.highlight(3);        if (count == 1) {          h = 4;          count = 2;          countsize = h;          codePart = 4;          return;        }        if (count == 2) {          h = 1;          count = 0;          countsize = h;          codePart = 4;          return;        }      case 4:        if (countsize < aSize) {          codePart = 5;          countsize++;        }        else {          codePart = 2;        }        codePanel.highlight(4);        return;      case 5:        if (theArray[countsize].getHeight() <=            theArray[countsize - h].getHeight()) {          codePart = 6;        }        else {          codePart = 4;        }        codePanel.highlight(5);        return;      case 6:        theArray[aSize + 1] = theArray[countsize];        theArray[countsize] = null;        codePart = 7;        codePanel.highlight(6);        j = countsize - h;        oldcodePart = 6;        return;      case 7:        if (j > 0 && theArray[aSize + 1].getHeight() < theArray[j].getHeight()) {          codePart = 8;        }        else {          codePart = 9;        }        codePanel.highlight(7);        return;      case 8:        theArray[j + h] = theArray[j];        theArray[j] = null;        j -= h;        codePart = 7;        oldcodePart = 8;        codePanel.highlight(8);        return;      case 9:        theArray[j + h] = theArray[aSize + 1];        theArray[aSize + 1] = null;        codePanel.highlight(9);        codePart = 4;        oldcodePart = 9;        return;      case 11:        codePanel.highlight(11);        doneFlag = true;    }  }  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; //左边x轴的开始位置  private final int textHeight = 13;  private int aSize = 10;  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; //画的方式  CodeAnimationPanel codePanel; //代码面板  int count = 1;  int countsize;  int j;  int oldcodePart = 0;  Color color;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -