```public static void quickSort2(int[] sourse, int low, int high)
{
if(low>high)
return;
int pivot=sourse[low];
int i=low;
int j=high;
if(i<j)
{
while(i<j)
{
while(sourse[i]<pivot&&i<high)
{
i++;
}
while(sourse[j]>pivot&&j>low)
{
j--;
}
if(i<j)
{
swap(sourse,i,j);
}
}
if(i>j)
swap(sourse,low,j);

quickSort2(sourse,low,j-1);
quickSort2(sourse,j+1,high);
}
}

public static void main(String[] args)
{
int[] sourse ;

sourse=new int[]{1,23,5,-2,-45,73,9,4,7,12,47,126,0,71,40,51,99};
quickSort2(sourse, 0, sourse.length-1);
System.out.println("快速排序：");
printArray(sourse);// 输出到转后数组的值

}```

ps:谢谢一楼的回复，三楼有正确答案，这个快速排序和书上一般见到的不太一样，自己看吧。

```public static void quickSort2(int[] sourse, int low, int high)
{
//System.out.println("基准值:"+sourse[low]);
int i=low;
int j=high;
if(i<j)
{
int pivot=sourse[low];
while(i<j)
{

while(sourse[i]<= pivot&&i<j)
{
i++;
}
while(sourse[j]>pivot&&i<j)
{
j--;
}
if(i<j)
{
swap(sourse,i,j);
}

}

if(pivot<sourse[i])
i--;

swap(sourse,low,i);

quickSort2(sourse,low,i-1);
quickSort2(sourse,i+1,high);
}
}
public static void main(String[] args)
{
int[] sourse ;

sourse = createArray(20);
//sourse=new int[]{1,23,5,-2,-45,73,9,4,7,12,47,126,0,71,40,51,99,99,40,7,12,126};
quickSort2(sourse, 0, sourse.length-1);
System.out.println("快速排序：");
printArray(sourse);// 输出到转后数组的值

}```

2个回答

int[] sourse=new int[]{1,23,5,-2,-45,73,9,4,7,12,47,126,0,71,40,51,99};

``````     for (int i = sourse.length-1; i >0; i--) {
for (int j = 0; j < i; j++) {
if(sourse[j]>sourse[j+1]){
int temp=0;
temp=sourse[j];
sourse[j]=sourse[j+1];
sourse[j+1]=temp;
}
}
}

for (int i = 0; i < sourse.length; i++) {
System.out.println(sourse[i]);
}
``````