Given an integer array, all negative values are transferred to the left of the array, and all positive values are transferred to the right. For example: 1,-2,-4, 5, 9, 3,-8, 6, after adjustment can be-2,-4, 3,-8, 1, 5, 9, 6.
The specific implementation code is as follows:
Package com.threeTop.www;
/***
* Array positive negative order
* @author WJGS * * * */Public
class ArraySort {
/**
* Draw on the idea of a quick sort, sort
* @ param Array
*
/public static void Sort (int [] array)
{
int i=0;
int j=array.length-1;
while (I!=j)
{while
(i<j&&array[i]<0)
{
i++
}
while (i<j&&array[j]>0)
{
j--
}
Exchange if
(i<j)
{
int temp=array[i]
If the above condition is not satisfied; ARRAY[I]=ARRAY[J];
Array[j]=temp
}
}
System.out.println ("Draw upon the sort of quick sort of results as follows:");
for (int k=0;k<array.length;k++)
{
System.out.print (array[k]+ ",");
}
}
public static void Main (string[] args) {
int []array={1,-2,-4,5,9,-3,-8,6};
Arraysort.sort (array);
}
}