package shan.com;

public class maopao ...{

/** *//**
* @param args
*/
public static void main(String[] args) ...{
// TODO 自動生成されたメソッド・スタブ
maopao();
maopao2();
maopao3();
maopao4();
}

public static void maopao() ...{

double[] in = ...{ 1, 2, -3, 40, 6, 8, 4, 5 };
int temp;
for (int i = 0; i < in.length; i++) ...{
for (int j = i; j < in.length; j++) ...{
if (in[j] < in[i]) ...{
temp = (int) in[j];
in[j] = in[i];
in[i] = temp;
}
}
}
for (int i = 0; i < in.length; i++)
System.out.println(in[i]);
System.out
.println("**************************************************************************************************");
}

public static void maopao2() ...{

double[] in = ...{ 1, 2, -3, 40, 6, 8, 4, 5 };
int temp;
for (int i = 0; i < in.length; i++) ...{
for (int j = i; j < in.length; j++) ...{
if (in[j] < in[i]) ...{
temp = (int) in[i];
in[i] = in[j];
in[j] = temp;
}
}
}
for (int i = 0; i < in.length; i++)
System.out.println(in[i]);
System.out
.println("**************************************************************************************************");
}

public static void maopao3() ...{

double[] in = ...{ 1, 2, -3, 40, 6, 8, 4, 5 };
int temp;
for (int i = 0; i < in.length; i++) ...{
for (int j = i; j < in.length; j++) ...{
if (in[j] > in[i]) ...{
temp = (int) in[j];
in[j] = in[i];
in[i] = temp;
}
}
}
for (int i = 0; i < in.length; i++)...{
System.out.println(in[i]);
try...{
Thread.sleep(1000);

}catch(Exception e)...{
System.out.println(e.toString());
}
}
System.out
.println("**************************************************************************************************");
}

public static void maopao4() ...{

double[] in = ...{ 1, 2, -3, 40, 6, 8, 4, 5 };
int temp;
for (int i = 0; i < in.length; i++) ...{
for (int j = i; j < in.length; j++) ...{
if (in[j] > in[i]) ...{
temp = (int) in[i];
in[i] = in[j];
in[j] = temp;
}
}
}
for (int i = 0; i < in.length; i++)
System.out.println(in[i]);
System.out
.println("**************************************************************************************************");
}
}
本文介绍了一种经典的排序算法——冒泡排序,并通过四个不同的方法进行了实现。这些方法展示了如何使用双层循环比较并交换数组中的元素,从而将数组按升序或降序排列。此外,还介绍了如何在排序过程中加入暂停效果。
39万+

被折叠的 条评论
为什么被折叠?



