public class test { public int[]arr; public int length; public test(int size){ this.length=size; Random random=new Random(); arr=new int[size]; for (int i = 0; i <size ; i++) { arr[i]=random.nextInt(101); } }
//快速排序(升序)
public void quick(int left int right){
int l =left;
int r =right;
if(l>r){
return; //结束递归
}
boolean flag=false;
while(l<r){
if(arr[l]>arr[r]){
int temp=arr[l];
arr[l]=arr[r];
arr[r]=temp;
flag=!flag
}
if(flag){
l++;
}else{
r--;
}}
l--;
r++;
quick(left,l);
quick(r,right);}
//选择排序 public void option(){ for (int i=0;i<pos-1;i++){ int max =i; for (int j=i+1;j<pos;j++){ if (arr[max]<arr[j]){ max=j; } }if (i!=max){ int temp =arr[i]; arr[i]=arr[max]; arr[max]=temp; }} }
//冒泡排序 public void popo(){ for (int i=0;i<pos-1;i++){ for (int j=0;j<pos-1-i;j++){ if (arr[j]>arr[j+1]){ int temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } }
//显示数组信息
public void display(){ for (int num:arr){ System.out.print(num+" "); } System.out.println(); }