zoukankan      html  css  js  c++  java
  • java冒泡排序

    1. public class Maopao {  
    2.     public static void main(String[] args) {  
    3.         int[] array={1,2,5,3,10,21,0};  
    4.         getSortD_X(array);  
    5.         getSortX_D(array);  
    6.     }  
    7.     public static void getSortD_X(int[] array){  
    8.         for (int i = 0; i array.length; i++) {  
    9.             for(int j=0;j<array.length-1;j++){  
    10.                 if(array[i]>array[j]){  
    11.                     int temp=array[i];  
    12.                     array[i]=array[j];  
    13.                     array[j]=temp;  
    14.                 }  
    15.             }  
    16.         }  
    17.         System.out.print("从大到小:");  
    18.         for (int i = 0; i array.length; i++) {  
    19.             if(i==array.length-1){  
    20.                 System.out.println(array[i]);  
    21.             }else{  
    22.                 System.out.print(array[i]+",");  
    23.             }  
    24.         }  
    25.     }  
    26.     public static void getSortX_D(int[] array){  
    27.         for (int i = 0; i <array.length; i++) {  
    28.             for(int j=0;j<array.length-i-1;j++){  
    29.                 if(array[j]>array[j+1]){  
    30.                     int temp=array[j];  
    31.                     array[j]=array[j+1];  
    32.                     array[j+1]=temp;  
    33.                 }  
    34.             }  
    35.         }  
    36.         System.out.print("从小到大:");  
    37.         for (int i = 0; i array.length; i++) {  
    38.             if(i==array.length-1){  
    39.                 System.out.println(array[i]);  
    40.             }else{  
    41.                 System.out.print(array[i]+",");  
    42.             }  
    43.         }  
    44.     }  
    45. }
  • 相关阅读:
    linux基础命令:alias
    linux基础命令:find
    Linux下which、whereis、locate命令的区别
    逆元知识普及(进阶篇) ——from Judge
    BZOJ 3620: 似乎在梦中见过的样子
    HDU contest808 ACM多校第7场 Problem
    P3203 [HNOI2010]弹飞绵羊 —— 懒标记?分块?LCT?...FAQ orz
    可持久化数组(线段树)[模板题]
    可持久化并(xian)查(duan)集(shu)
    主席树(静态)的轻松入门
  • 原文地址:https://www.cnblogs.com/Yxxxxx/p/6858671.html
Copyright © 2011-2022 走看看