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

     1 public class BubbleSortDemo {
    2
    3 /**
    4 * @param args
    5 */
    6 public static void main(String[] args) {
    7 // TODO Auto-generated method stub
    8 int []ary=new int[]{2,1,4,3,7,5,6,9};
    9 ary=bubblesort(ary);
    10 for (int i = 0; i < ary.length; i++) {
    11 System.out.print(ary[i] + " ");
    12 }
    13 }
    14
    15 public static int[] bubblesort(int []ary)
    16 {
    17 for(int i=0;i<ary.length-1;i++)
    18 {
    19 for(int j=0;j<ary.length-i-1;j++)
    20 {
    21 if(ary[j]>ary[j+1])
    22 {
    23 int temp = ary[j];
    24 ary[j] = ary[j+1];
    25 ary[j+1] = temp;
    26 }
    27 }
    28 }
    29 return ary;
    30 }
    31 }

      

  • 相关阅读:
    BZOJ
    BZOJ
    BZOJ
    BZOJ
    BZOJ
    BZOJ
    [知识点]平衡树之Splay
    [BZOJ1015/JSOI2008]星球大战
    [知识点]状态压缩DP
    [NOIP2011]聪明的质检员
  • 原文地址:https://www.cnblogs.com/superjt/p/2116816.html
Copyright © 2011-2022 走看看