Java: How to sort part of a 3d array? -
i have array: array[2][7][2]
.
for (int = 0; < 2; i++) { (int j = 0; j < 7; j++) { syso(array[i][j][0] + " "); } syso("/n"); }
currently above code prints out:
4 1 2 5 9 0 1
2 3 1 9 9 3 1
is there way have these sorted somehow? don't care array[i][j][1]
, array[i][j][0]
.
i wrote myself quicksort function random piece of code doesn't work:
for (int = 0; < array.length; i++) { quicksort(array[i][0], 0, array[i].length - 1); }
edit:
here's quicksort function well:
static int partition(int a[], int l, int r) { int pivot = a[r]; int k=l-1; for(int i=l; <= r; i++) { if (a[i] <= pivot) { k++; int w = a[i]; a[i] = a[k]; a[k] = w; } } return k; } static void quicksort(int [] a, int l, int r) { if (l>=r) { return ; } int k = partition(a, l, r); quicksort(a, l, k-1); quicksort(a, k+1, r); }
int[][] = int[2][7]; (int = 0; < array.length; i++) { (int j = 0; j < array.length; j++) { anotner[i][j] = array[i][j][0]; } } (int[] : anotner) { arrays.sort(a); }
then print anotner
using syso()
.
Comments
Post a Comment