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

    1、升序如下:

    package lxyq;

    public class Test {

    public static void sort(int[] array) // 排序
    {
    for (int i = 0; i < array.length; i++) {
    for (int j = i + 1; j < array.length; j++) {
    System.out.println(j+"<<>>>"+i);
    if (array[j] < array[i]) {
    int temp = array[j];
    array[j] = array[i];
    array[i] = temp;
    }
    }
    }
    }
    public static void main(String[] args) {
    int[] a = { 1, 6, 2, 0 };
    sort(a);
    for (int i = 0; i < a.length; i++) {
    System.out.println(a[i]);
    }
    }
    }

    2、降序如下:

    package lxyq;

    public class Test {

    public static void sort(int[] array) // 排序
    {
    for (int i = 0; i < array.length; i++) {
    for (int j = i + 1; j < array.length; j++) {
    System.out.println(j+"<<>>>"+i);
    if (array[j] > array[i]) {
    int temp = array[j];
    array[j] = array[i];
    array[i] = temp;
    }
    }
    }
    }
    public static void main(String[] args) {
    int[] a = { 1, 6, 2, 0 };
    sort(a);
    for (int i = 0; i < a.length; i++) {
    System.out.println(a[i]);
    }
    }
    }

  • 相关阅读:
    MFC绘图基础
    MFC绘图基础
    MFC坐标问题
    利用Graphziv帮助理解复杂的类层次关系
    priority_quenue
    1060. Are They Equal (25)
    1057. Stack (30)
    1056. Mice and Rice (25)
    1053. Path of Equal Weight (30)
    1051. Pop Sequence (25)
  • 原文地址:https://www.cnblogs.com/flywang/p/5480855.html
Copyright © 2011-2022 走看看