High-speed Sequencing Java language implementation

Source: Internet
Author: User

this blog is no longer updated, many other wonderful content please visit my Independent Blog


High-speed sequencing is a very important sorting algorithm, but when I was learning, I found that there are no particularly good examples on the Internet, so I wrote one.

Get your hands on your own.


Package Sort;import Java.util.random;public class QuickSort {@SuppressWarnings ("unused") Public boolean Inittestarray ( Int[] testarray) {//Initialize testarrayif (Testarray = = null) return false; Random random = new random (), for (int i = 0; i < testarray.length; i++) {Testarray[i] = Random.nextint (200);} return true;} public boolean Printtestarray (int[] testarray) {//print content in Testarray if (Testarray = = null) return false;for (int i = 0; I &lt ; Testarray.length; i++) {System.out.print (Testarray[i] + ",");} System.out.println (); return true;} public static Boolean QuickSort (int[] testarray, int left, int. right) {if (testarray==null) return false;if (left < right {int pivotpos = Quicksort.partition (Testarray, left, right); Quicksort.quicksort (Testarray, left, pivotpos-1); Quicksort.quicksort (Testarray, Pivotpos + 1, right);} return true;} public static int partition (int[] Testarray, int. Low, int.) {int i = low, j = high, pivot = Testarray[low],temp=0;whil E (i < J) {while (I < J && TestarRAY[J] >= pivot) j--;while (i < J && Testarray[i] <= pivot) i++;temp = testarray[i];testarray[i] = Testarra Y[J];TESTARRAY[J] = temp;} Testarray[low] = Testarray[i];testarray[i] = Pivot;return i;} public static void Main (String args[]) {int[] Testarray = new INT[20]; QuickSort QuickSort = new QuickSort (); Quicksort.inittestarray (Testarray); System.out.println ("Pre-order:"); Quicksort.printtestarray (Testarray); Quicksort.quicksort (Testarray, 0, testarray.length-1)) System.out.println ("Sorting Error!

"); System.out.println ("After sorting:"); Quicksort.printtestarray (Testarray);}}



High-speed Sequencing Java language implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.