package test;
//遍历输出
public class BaseSort {
public void sort(int[] a){
for (int i:
a) {
System.out.print(i + " ");
}
System.out.println();
}
}
package test;
public class Factory {
private BaseSort sort;
public void setSort(BaseSort sort){
this.sort = sort;
}
public void doSort(int[] a){
sort.sort(a);
}
}
package test;
//未完成
public class InsertSort extends BaseSort {
}
package test;
//未完成
public class QuickSort extends BaseSort{
}
package test;
//选择排序
public class SelectSort extends BaseSort{
public void sort(int[] a){
int temp;
for (int i = 0; i < a.length - 1; i++) {
for (int j = i+1; j < a.length; j++) {
if(a[i] < a[j]){
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
BaseSort show = new BaseSort();
show.sort(a);
}
}
//以下为主函数
package test;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] num = new int[n];
for (int i = 0; i < n; i++) {
num[i] = scanner.nextInt();
}
Factory factory = new Factory();
BaseSort selectsort = new SelectSort();
factory.setSort(selectsort);
factory.doSort(num);
}
}
!未完成!插入排序,快速排序未完成