bubblesorter.java~7~

来自「《深入浅出设计模式》的完整源代码」· JAVA~7~ 代码 · 共 21 行

JAVA~7~
21
字号
package bubblesorter;
//
public abstract class BubbleSorter {
  private int operations = 0;
  protected int length = 0;
  protected int doSort () {
    operations = 0;
    if (length <= 1)
      return operations;
    for (int nextToLast = length - 2;
         nextToLast >= 0; nextToLast--)
      for (int index = 0; index <= nextToLast; index++) {
        if (outOfOrder (index))
          swap (index);
        operations++;
      }
    return operations;
  }
  protected abstract void swap (int index);
  protected abstract boolean outOfOrder (int index);
}

⌨️ 快捷键说明

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