java程式設計:用氣泡排序實現升序排列和降序排列

來源:酷知科普網 3.31W

12,45,9,67,455,用氣泡排序實現升序排列

操作方法

(01)package huo;public class Test05 {public static void main(String[] args) ;for (int i = 0; i < th - 1; i++) {for (int j = 0; j < th - 1 - i; j++) {if (arr[j] > arr[j + 1]) {int temp;temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}}tln("排序後:");for (int i = 0; i < th; i++)t(arr[i] + "t");}}

java程式設計:用氣泡排序實現升序排列和降序排列

特別提示

若要實現降序排列,只需將arr[j] &gt; arr[j + 1]中的&quot;&gt;&quot; 改為&quot;

熱門標籤