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. }
  • 相关阅读:
    使用Leangoo玩转故事地图
    用Leangoo做敏捷需求管理
    LEANGOO成员
    LEANGOO卡片
    给WebAPI的REST接口添加测试页面(三)
    使用Win2D在UWP程序中2D绘图(二)
    Visual Studio 2015的“转到定义”和“查看定义”出错的Bug
    使用Win2D在UWP程序中2D绘图(一)
    Windows 10 UWP程序标题栏设置
    .NET 4.6的RyuJIT尾递归优化的Bug
  • 原文地址:https://www.cnblogs.com/Yxxxxx/p/6858671.html
Copyright © 2011-2022 走看看