Java Algorithm interview questions: What are the methods for sorting? List. Use JAVA to implement a fast sorting. Select bubble quick set to sort by at least four methods, java Algorithm
Package com. swift; import java. util. arrayList; import java. util. collections; import java. util. comparator; import java. util. list; public class QuickSort {/** Quick Sort */public static void main (String [] args) {String [] strVoid = new String [] {"11 ", "66", "22", "0", "55", "22", "0", "32"}; QuickSort sort = new QuickSort (); sort. quickSort (strVoid, 0, strVoid. length-1); for (int I = 0; I <strVoid. length; I ++) {System. out. println (strVoid [I] + "") ;}// sort List by comparator <String> list = new ArrayList <String> (); for (String str: strVoid) {list. add (str);} Collections. sort (list, new Comparator <String> () {@ Override public int compare (String arg0, String arg1) {int num = arg1.compareTo (arg0); return num ;}}); for (String str: list) {System. out. print (str + "|") ;}} public void quickSort (String [] strDate, int left, int right) {String middle, tempDate; int I, j; I = left; j = right; middle = strDate [(I + j)/2]; do {while (strDate [I]. compareTo (middle) <0 & I <right) I ++; // find the number on the left greater than the median while (strDate [j]. compareTo (middle)> 0 & j> left) j --; // find a number smaller than the median on the right if (I <= j) {// Replace the large and small numbers on the left with tempDate = strDate [I]; strDate [I] = strDate [j]; strDate [j] = tempDate; I ++; j -- ;}}while (I <= j); // when the two are staggered, stop if (I <right) {quickSort (strDate, I, right ); // slave} if (j> left) {quickSort (strDate, left, j );}}}