import java.util.Stack;
public static final int[] quickSort(int[] data){
Stack stack=new Stack();
int temp;
int i,j,left,right;
stack.push(new Integer(data.length-1)); //push right
stack.push(new Integer(0)); //push left
do{
left=((Integer)stack.pop()).intValue(); //pop left
right=((Integer)stack.pop()).intValue(); //pop right
i=left+1;
j=right;
while(j>i){
while(data[i] < data[left])
if(i data[left])
if(j>left+1) j--;
else break;
if(j>i){
temp = data[j];
data[j] = data[i];
data[i] = temp;
}
}
if(data[j] < data[left]){
temp = data[j];
data[j] = data[left];
data[left] = temp;
}
if(j>left){
stack.push(new Integer(j-1)); // push right
stack.push(new Integer(left)); // push left
}
if(j0);
return data;
}
public static final int[] quickSort(int[] data){
Stack stack=new Stack();
int temp;
int i,j,left,right;
stack.push(new Integer(data.length-1)); //push right
stack.push(new Integer(0)); //push left
do{
left=((Integer)stack.pop()).intValue(); //pop left
right=((Integer)stack.pop()).intValue(); //pop right
i=left+1;
j=right;
while(j>i){
while(data[i] < data[left])
if(i data[left])
if(j>left+1) j--;
else break;
if(j>i){
temp = data[j];
data[j] = data[i];
data[i] = temp;
}
}
if(data[j] < data[left]){
temp = data[j];
data[j] = data[left];
data[left] = temp;
}
if(j>left){
stack.push(new Integer(j-1)); // push right
stack.push(new Integer(left)); // push left
}
if(j0);
return data;
}
解决方案 »
- 使用数据库连接池方式编码的时候为什么要close()
- 重写equals()!
- 如何统计list中对象的某个属性值...
- struts中使用logic:iterator和bean:write输出查询结果集的问题
- 谁帮我看看这个书上的例子
- 怎样解决数值转化中的丢失回题?
- 王开福来拿分!
- 在线等待,怎样用html调用我自己的类(从JApplet派生的)、急!急!急!急!急!
- 如何才能成为一名java程序员???
- 请问,如何获得某个目录下所有的文件名,包括子目录的。
- 关于单向链表的问题。
- ~~~~谁知道jbuilderx 怎么让tab键=format???~~~~谁知道jbuilderx 怎么让tab键=format???~~~~
int i,j,k;
int Pivot;
int Temp;
i=Left;
j=Right+1;
Pivot=Data[Left];
if(i<j){
do{
do{
i++;
}while(Data[i]<=Pivot&&i<=Right);
do {
j--;
}while(Data[i]>=Pivot&&j>Left);
if(i<j){
Temp=Data[i];
Data[i]=Data[j];
Data[j]=Temp;
}
}while(i<j);
if(i>j){
Temp=Data[Left];
Data[Left]=Data[j];
Data[j]=Temp;
System.out.print("Current sorting result:");
for(k=0;k<Index;k++){
System.out.print(""+Data[k]+"");
}
System.out.println("");
}
QuickSort(Left,j-1,Index);
QuickSort(j+1,Right,Index);
}
}
}
...
Array.sort(a)