一、代码展示:
package comployeetest; public class Test1 { public static void main(String[] args) { int[] arr = { 0, -2, 3,0,0,0, 4, 0, 1, 0, -1, 0, 3 }; order(arr); for (int i : arr) { System.out.print(i + ","); } } public static void order(int[] arr) { int j = arr.length - 1; int i = 0; int temp; while (i < j) { if (arr[j] == 0) { j--; continue; } if (arr[i] == 0) { temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; j--; } i++; } } }
二、结构展示: