zoukankan      html  css  js  c++  java
  • 七大基本排序算法之冒泡排序

    import java.io.IOException;
    import Input.InputString;
     
    /**
     * 冒泡排序
     * @author xiaomi
     * 2012.3.29
     */
    public class BubbleSort {
        public static void main(String[] args) throws IOException{
            String s = InputString.getString();
            String[] str = s.split(" ");
            int[] a = new int[str.length];
            for(int i = 0;i < str.length;i++){
                a[i] = Integer.parseInt(str[i]);
            }
            bubbleSort(a);
            for(int i = 0;i < a.length;i++){
                System.out.print(a[i]+" ");
            }
        }
         
        public static void bubbleSort(int[] a){
            for(int i = 0;i < a.length;i++){
                for(int j = a.length-1;j > i;j--){
                    if(a[j]<a[j-1]){
                        int temp = a[j];
                        a[j] = a[j-1];
                        a[j-1] = temp;
                    }
                }
            }
        }
    }
  • 相关阅读:
    事后诸葛亮
    冲刺总结
    Alpha第十天
    Alpha第八天
    Alpha第九天
    Alpha第六天
    Alpha第七天
    Alpha第五天
    Python之pytesseract模块-实现OCR
    Selenium4 IDE初体验
  • 原文地址:https://www.cnblogs.com/williamxiao/p/3499949.html
Copyright © 2011-2022 走看看