main
kgdxpr 2 years ago
parent 9178efeea4
commit 66f0654fd9

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 226 KiB

@ -2,9 +2,51 @@ package UnitTest;
import com.dsideal.FengHuang.Util.CommonUtil; import com.dsideal.FengHuang.Util.CommonUtil;
import java.util.Arrays;
public class TestC { public class TestC {
public static String[] sortByName(String[] names, int[] heights) {
quickSort(names, heights, 0, heights.length - 1);
return names;
}
private static void quickSort(String[] names, int[] heights, int start, int end) {
if (start >= end) {
return;
}
int pivot = partition(names, heights, start, end);
quickSort(names, heights, start, pivot - 1);
quickSort(names, heights, pivot + 1, end);
}
private static int partition(String[] names, int[] heights, int start, int end) {
int pivotHeight = heights[end];
int i = start - 1;
for (int j = start; j < end; j++) {
if (heights[j] >= pivotHeight) {
i++;
int tmpHeight = heights[i];
heights[i] = heights[j];
heights[j] = tmpHeight;
String tmpName = names[i];
names[i] = names[j];
names[j] = tmpName;
}
}
int tmpHeight = heights[i + 1];
heights[i + 1] = heights[end];
heights[end] = tmpHeight;
String tmpName = names[i + 1];
names[i + 1] = names[end];
names[end] = tmpName;
return i + 1;
}
public static void main(String[] args) { public static void main(String[] args) {
String t= CommonUtil.getLdapPassword("Xyy199191"); String[] names = {"Mary", "John", "Emma"};
System.out.println(t); int[] heights = {180, 165, 170};
String[] sortedNames = sortByName(names, heights);
System.out.println(Arrays.toString(sortedNames));
} }
} }

Loading…
Cancel
Save