用JAVA写了个快速排序,不知道为什么总不对

来源:百度知道 编辑:UC知道 时间:2024/05/19 06:32:05
public class Quick-sort{
public Quick-sort(){
}
public int[] sortASC(int[] datasort){
if(datasort=null)
return null;
else
{
int size=datasort.length;
Quick-sort(datasort[],0,size-1);
return datasort[];
}
}
public Quick-sort(int[] numsort,int low,int high){
if(low<high){
int pos=partition(numsort[]);
Quick-sort(numsort,0,pos-1);
Quick-sort(numsort,pos+1,high);
}
return numsort[];
}
public int partition(int numsort[],int low,int high){
int pos=low;
int temp=numsort[low];
for(int i=low+1;i<=high;i++){
if(numsort[i]<temp){
swap(temp,numsort[i]);
pos++;
}
}
swap(numsort[low],numsort[pos]);
}

public void swap(int a,int b){
int temp;
temp=a;
a=b;
b=temp;
}
public static void main(String[] args){

我晕,一个简单的数字排序,有必要写成这样吗?随便看写就发现有很的基础性错误,比如:类名错误,不能用“-”;判断数组是否为空时,应用“==”;main方法直接调用排序方法时,必须把该方法定义为静态才行啊……
随便写了个简单点的,参考一下:
public class MyListUtil {

public static void main(String[] args) {
int[] a = {3,1,5,12,-22,2,50,-4,21,33};
for (int i = 0; i < queue(a).length; i++) {
System.out.println(queue(a)[i]+", ");
}
}

public static int[] queue(int[] a){
for (int i = 0; i < a.length; i++) {
for (int j = a.length-1; j >= 1; j--) {
if(a[j] < a[j-1]) {
int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
}
return a;
}
}

Quick-sort文件名违法