1. 程式人生 > 其它 >【轉】執行維護管理制度 【轉】執行維護管理制度

【轉】執行維護管理制度 【轉】執行維護管理制度

/*姓名 :趙康樂

職業 :學生

日期 :2022-04-14

任務 :用java語言編寫氣泡排序,插入排序和快速排序。

*/

public class sort {
static void bubbleSort(int[] a){
//氣泡排序
for(int i=0;i<a.length;i++){
for(int j=0;j<a.length-i-1;j++){
if(a[j]>a[j+1]){
int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
static void InsertSort(int[] a){
//插入排序
for(int i=1;i<a.length;i++){
int temp = a[i];
int j = i-1;
for(;j>=0&&a[j]>temp;j--){
a[j+1] = a[j];
}
a[j+1] = temp;
}
}
static void QuickSort(int[] a,int left,int right){
//快速排序
if(right-left<=0){
return;
}
int standard = a[left];
int low = left+1;
int high = right;
while(low<=right){
if(a[low]<standard){
low++;
}else{
int temp = a[low];
a[low] = a[high];
a[high] = temp;
high--;
}
}
int temp = a[left];
a[left] = a[high];
a[high] = temp;
QuickSort(a,left,high);
QuickSort(a,high+1,right);
}
}