java冒泡快速代码 java编写冒泡算法( 二 )


运行结果如下(Bubble类为核心算法类):
************************************
run:
请输入您将要输入整数的个数:
10
请输入一串数字进行冒泡排序,注意:每次只输入一个,输完则回车
1:10
2:23
3:11
4:56
5:45
6:26
7:59
8:28
9:84
10:79
初始序列的数组为:
10 23 11 56 45 26 59 28 84 79
学号:200815009* 班级:08软件3班 姓名:叶科良
排序好的数组为:
10 11 23 26 28 45 56 59 79 84
源代码如下:
***************************************************
package testBubble;
import java.io.Reader;
import java.util.Scanner;
/**
*
* @author yekeliang
*/
public class TestBubble {
private CommandLineBubbleRunner commandLineBubbleRunner;
private int arraySize;
private int[] intArray;
private StuInfo stuInfo;
private Info info;
/**
* 测试方法
* @param args
*/
public static void main(String[] args) {
TestBubble test = new TestBubble();
}
/**
* 构造方法
* 调用初始化学生数据、接收命令行整数、展示结果3个成员方法
*/
public TestBubble() {
initMemb();
initData();
runBubble();
showResult(this.getIntArray());
}
/**
* 初始化学生数据
*/
private void initData() {
stuInfo.setStuNum("200815009*");
stuInfo.setStuClass("08软件3班");
stuInfo.setStuName("叶科良");
info.setInputIntNumInfo("请输入您将要输入整数的个数:");
info.setInputIntInfo("请输入一串数字进行冒泡排序 , 注意:每次只输入一个 , 输完则回车");
info.setShowInputInfo("初始序列的数组为:");
info.setShowResultInfo("排序好的数组为:");
info.setInputErrorInfo("对不起 , 输入有误!请输入整数.");
}
/**
* 接收命令行整数 , 使用冒泡算法
*/
private void runBubble() {
try{
System.out.println(info.getInputIntNumInfo());
setArraySize(getCommandLineBubbleRunner().getArraySize());
System.out.println(info.getInputIntInfo());
setIntArray(getCommandLineBubbleRunner().getAcceptAsIntArray(getArraySize()));
System.out.println(info.getShowInputInfo());
getCommandLineBubbleRunner().showAcceptAsIntArray(getIntArray());
Bubble.quick(getIntArray());
} catch(java.util.InputMismatchException e) {
System.out.println(info.getInputErrorInfo());
}
}
/**
* 展示结果
*/
private void showResult(int intArray[]) {
System.out.println("\n" + stuInfo.toString());
System.out.println(info.getShowResultInfo());
for (int i = 0; iintArray.length; i++) {
System.out.print(intArray[i] + " ");
}
}
private void initMemb() {
stuInfo = new StuInfo();
info = new Info();
commandLineBubbleRunner = new CommandLineBubbleRunner();
}
public CommandLineBubbleRunner getCommandLineBubbleRunner() {
【java冒泡快速代码 java编写冒泡算法】return commandLineBubbleRunner;
}
public void setCommandLineBubbleRunner(CommandLineBubbleRunner commandLineBubbleRunner) {
this.commandLineBubbleRunner = commandLineBubbleRunner;
}
public int getArraySize() {
return arraySize;
}
public void setArraySize(int arraySize) {
this.arraySize = arraySize;
}
public int[] getIntArray() {
return intArray;
}
public void setIntArray(int[] intArray) {
this.intArray = intArray;
}
private void getStuInfo() {}
}
/**
*
* @author 叶科良
*/
class CommandLineBubbleRunner {

推荐阅读