LoginSignup
0
0

More than 3 years have passed since last update.

java バブルソート

Posted at

ソート

今回からソートについて投稿していこうと思います。
※自分のアウトプット用の記事です。間違いなどがあったら指摘してください。

バブルソート

BubbleSort.java
public class BubbleSort {
    public static void sort(int[] array) {
        for(int i=0;i<array.length;i++) {
            for (int j=0;j<array.length-1;j++) {
                if(array[j]>array[j+1]) {
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }
    }
    public static void main(String args[]) {
        int[] array = {5,4,3,2,1};
        sort(array);
        for(int i=0;i<array.length;i++) {
            System.out.print(array[i]);
        }
    }
}

今回はバブルソートを試してみました。次回は選択ソートを投稿しようと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0