zoukankan      html  css  js  c++  java
  • 案例:java中的基本排序

     1 //冒泡排序
     2 
     3 
     4 import java.util.Arrays;
     5 
     6 
     7 public class ForTest{
     8     public static void main(String args[]){
     9         int[] arr = {34,54,12,45,23};
    10         System.out.println(Arrays.toString(arr));
    11         for(int i = 0; i <arr.length - 1; i++){
    12             for(int j = 0; j < arr.length - 1 -i; j++){
    13                 if(arr[j]>arr[j+1]){
    14                     int t = arr[j];
    15                     arr[j] = arr[j+1];
    16                     arr[j+1] = t;
    17                 }
    18             }
    19         }
    20         System.out.print(Arrays.toString(arr));
    21 }
    22  }
    //选择排序
    import java.util.Arrays;
    
    
    public class ForTest{
        public static void main(String args[]){
            int[] arr ={23,345,654,12};
            System.out.print(Arrays.toString(arr));
            for(int i = 0; i <arr.length - 1; i++){
                for(int j = i + 1; j <arr.length;j++){
                    if(arr[i]>arr[j]){
                        int t = arr[i];
                        arr[i] = arr[j];
                        arr[j] = t;
                    }
                }
            }
            System.out.println(Arrays.toString(arr));
        }
    }
  • 相关阅读:
    EasyUI tab
    CC和他的AE86
    Spreading the Wealth UVA
    Ultra-QuickSort POJ
    区间完全覆盖问题(贪心)
    Mod Tree HDU
    Snakes and Ladders LightOJ
    There is no SSR CSU
    X问题 HDU
    斐波那契数列
  • 原文地址:https://www.cnblogs.com/YangGC/p/6077085.html
Copyright © 2011-2022 走看看