JAVA排序的方法
//冒泡排序法:
package fuxi;
public class Bubble {
?? ?public static void main(String[] args) {
?? ??? ?int a[] = { 10,23,11,56,45,26,59,28,84,79 };
?? ??? ?int i,temp;
?? ??? ?System.out.println("輸出原始數(shù)組數(shù)據(jù):");
?? ??? ?for (i=0; i<a.length; i++) {
?? ? ?? ??? ?System.out.print(a[i]+" ");
?? ? ?? ?}
?? ??? ?for (i=0; i<9; i++) {
?? ??? ??? ?if (a[i] > a[i+1]) {
?? ??? ??? ??? ?temp = a[i];
?? ??? ??? ??? ?a[i] = a[i+1];
?? ??? ??? ??? ?a[i+1] = temp;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?System.out.println("\n"+"排序號的數(shù)組數(shù)據(jù)為:");
?? ??? ?for (i=0; i<a.length; i++) {
?? ? ?? ??? ?System.out.print(a[i]+" ");
?? ? ?? ?}
?? ?}
}
//選擇排序方法
package fuxi;
public class Bubble {
?? ?public static void main(String[] args) {
?? ??? ?int a[] = { 10,23,11,56,45,26,59,28,84,79 };
?? ??? ?int i,temp;
?? ??? ?System.out.println("輸出原始數(shù)組數(shù)據(jù):");
?? ??? ?for (i=0; i<a.length; i++) {
?? ? ?? ??? ?System.out.print(a[i]+" ");
?? ? ?? ?}
?? ??? ?for (i=0; i<9; i++) {
?? ??? ??? ?if (a[i] > a[i+1]) {
?? ??? ??? ??? ?temp = a[i];
?? ??? ??? ??? ?a[i] = a[i+1];
?? ??? ??? ??? ?a[i+1] = temp;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?System.out.println("\n"+"排序號的數(shù)組數(shù)據(jù)為:");
?? ??? ?for (i=0; i<a.length; i++) {
?? ? ?? ??? ?System.out.print(a[i]+" ");
?? ? ?? ?}
?? ?}
}
??? ?
??? ?
轉(zhuǎn)載于:https://www.cnblogs.com/changankaifazhe/p/10019962.html
總結(jié)
- 上一篇: 树的存储
- 下一篇: adb connect 192.168.