/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(final int[] sortVal, final boolean asc) { return qSort(sortVal, asc); }
/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(final List<Integer> sortVal, final boolean asc) { return qSort(sortVal, asc); }
/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(int[] sortVal, boolean asc) { return qSort(sortVal, asc); } /**
/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(List<Integer> sortVal, boolean asc) { return qSort(sortVal, asc); } public static int[] sortString(List<String> sortVal, boolean asc)
/** * Sort an integer array using Quick Sort. * @param l The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ private static int[] qSort(final int[] l, final boolean asc) { final int[] idx = new int[l.length]; List<Integer> idxList = new ArrayList<>(); for (int i = 0; i < l.length; i++) { idxList.add(i); } idxList = qSort(l, idxList, asc); for (int i = 0; i < l.length; i++) { idx[i] = idxList.get(i); } return idx; }
/** * Sort an integer array using Quick Sort. * @param l The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ private static int[] qSort(int[] l, boolean asc) { count = 0; int[] idx = new int[l.length]; List<Integer> idxList = new ArrayList<Integer>(); for(int i=0;i<l.length;i++) idxList.add(i); //System.out.print("Sorting..."); idxList = qSort(l, idxList, asc); for(int i=0;i<l.length;i++) idx[i] = idxList.get(i); //System.out.println("[Done.]"); return idx; } /**
/** * Quick sort internal * @param l The list to sort. * @param asc Ascending/Descendingly parameter. * @return The sorted indexes. */ private static int[] qSort(List<Integer> l, boolean asc) { count = 0; int[] idx = new int[l.size()]; List<Integer> idxList = new ArrayList<Integer>(); for(int i=0;i<l.size();i++) idxList.add(i); //System.out.print("Sorting..."); idxList = qSort(l, idxList, asc); for(int i=0;i<l.size();i++) idx[i] = idxList.get(i); //System.out.println("[Done.]"); return idx; } private static int[] qSortString(List<String> l, boolean asc)
/** * Quick sort internal * @param l The list to sort. * @param asc Ascending/Descendingly parameter. * @return The sorted indexes. */ private static int[] qSort(final List<Integer> l, final boolean asc) { final int[] idx = new int[l.size()]; List<Integer> idxList = new ArrayList<>(); for (int i = 0; i < l.size(); i++) { idxList.add(i); } idxList = qSort(l, idxList, asc); for (int i = 0; i < l.size(); i++) { idx[i] = idxList.get(i); } return idx; }