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
//基础类 public class basesort { public void sort(int[] arr) { System.out.println("排序算法"); } public void sort(int[] arr, int begin, int end) { System.out.println("重载排序算法"); } } //快速排序 public class quicksort extends basesort { public static int getMiddle(int []arr,int low ,int high){ int temp=arr[low]; while(low<high){ while(low<high&&arr[high]>=temp){ high--; } arr[low]=arr[high]; while(low<high&&arr[low]<temp){ low++; } arr[high]=arr[low]; } arr[low]=temp; return low; } } //选择排序 public class selsectsort extends basesory { 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 temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } } } //插入排序 public class insersort extends basesort { public static void insersort (int arr[]){ for(int i=1;i<arr.length;i++){ int temp=arr[i]; int j=i-1; for(j=i-1;j<=0&&arr[j]>temp;j--){ arr[j+1]=arr[j]; } arr[j+1]=temp; } } } //策略类 public class Factory { private basesort aort; //依赖注入 public void setSort(basesort sort){ this.sort;=sort; } public void doSort(int []arr){ sort.sort(arr); } public void doSort(int []arr,int begin,int end){ sort.sort(arr, begin ,end); } } //测试类 public class test { public static void main(String[] args){ int []arr=new int[10]; Scanner scanner=new Scanner(System .in); System.out.println("自己从键盘输入:"); for(int i=0;i<10;i++){ arr[i]=scanner.nextInt(); } Factory factory=new Factory(); basesort select_sort=new selsectsort(); factory.setSort(select_sort); factory.doSort(arr); } }
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: