Home > Back-end >  Want a quick sort, but I don't know where is the problem
Want a quick sort, but I don't know where is the problem

Time:04-01

Package java0331;

Public class EmpManager {
Public static void main (String [] args) {
Int people []=new int [10].
for (int i=0; I & lt; 10; I++) {
Int salary=(int) (Math. The random () * 5000 + 5000);
People [I]=salary;
}
For (int j=0; J & lt; People. Length; J++) {
System. The out. Println (j + 1 + "wages" respectively + people [j]);
}
Sort (people);
}

Public static int the sort (int [] salary) {

For (int j=0; J & lt; Salary. The length - 1; J++) {
Int start=salary [0];
For (int I=j + 1; I & lt; Salary. Length; I++) {
If (start & gt; Salary [I]) {
Start=salary [I];
}

}
If (start!=salary [0]) {
Int temp=start;
Start=salary [j];
Salary [j]=temp;
//System. Out. Println (start);
}
}
For (int c=0; C & lt; Salary. Length; C + +) {
System. The out. Println (salary) [c];
}
return 0;

}
}

CodePudding user response:

 public static void the sort (int [] salary) {
For (int j=0; J & lt; Salary. The length - 1; J++) {
for (int i=0; I & lt; Salary. The length - 1 - j; I++) {
If (salary [I] & gt; Salary [I + 1]) {
//if the first number is greater than the second number, then swap places
Int a=salary [I];
Salary [I]=salary [I + 1);
Salary [I + 1)=a;
}
}
}
System. The out. Println (" is sorted data: "+ salary. Length);
For (int I: salary) {
System. The out. Print (I + ", ");
}
}
  • Related