We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import java.util.Scanner; public class BaseSort { public void sort(int []a){ System.out.println("排序算法"); } } //选择排序 class SelectSort extends BaseSort{ @Override public void sort (int a[]){ for (int i = 0; i < 10; i++) { for (int j = i; j < 10; j++) { if(a[j] < a[i]) { a[i] =a[i] ^a[j]; a[j] =a[i] ^a[j]; a[i] =a[i] ^a[j]; } } } for (int j = 0; j < 10; j++) { System.out.print(a[j]+" "); } } } //插入排序 class InsertSort extends BaseSort{ } //快速排序 class QuickSort extends BaseSort{ } //策略类 class Factory{ private BaseSort sort; //依赖注入 public void setSort(BaseSort sort){ this.sort = sort; } public void doSort(int []a){ sort.sort(a); } } class Test{ public static void main(String[] args) { //自己用键盘输入 int a[10] int []a=new int[10]; Scanner s = new Scanner(System.in); for (int i = 0; i < 10 ; i++) { a[i] = s.nextInt(); } Factory factory = new Factory(); BaseSort select_sort = new SelectSort(); factory.setSort(select_sort); factory.doSort(a) ; } } ```java
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: