bubblesorter.java
来自「著名的uncle Bob的Agile software development的」· Java 代码 · 共 27 行
JAVA
27 行
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 + -
显示快捷键?