排序算法之冒泡排序,选择排序
生活随笔
收集整理的這篇文章主要介紹了
排序算法之冒泡排序,选择排序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public class Sort {public static void main(String[] args) {int[] arr = { 24, 69, 80, 57, 13 };bubbleSort(arr);selectSort(arr);for (int s : arr) {System.out.print(s + "/");}}//冒泡排序public static void bubbleSort(int[] arr) {for (int i = 0; i < arr.length - 1; i++) {for (int j = 0; j < arr.length - i - 1; j++) {if (arr[j] > arr[j + 1]) {int a = arr[j];arr[j] = arr[j + 1];arr[j + 1] = a;}}}}//選擇排序public static void selectSort(int[] 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 a = arr[i];arr[i] = arr[j];arr[j] = a;}}}}}
?
總結
以上是生活随笔為你收集整理的排序算法之冒泡排序,选择排序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java操作——获取文件扩展名,去掉文件
- 下一篇: 安装上 Octotree 插件让你更加方