Java for fast sorting

Source: Internet
Author: User
Public class qsort {/*** @ author ganjh 2010-08-09 * @ Param pdata the position on the left of the array to be sorted * @ Param left. The initial value is 0 * @ Param right, the initial value is the array length */public static void quicksort (INT [] pdata, int left, int right) {int I, j; int middle, temp; I = left; j = right; middle = pdata [left]; while (true) {While (++ I) <right-1 & pdata [I] <middle ); // start from the second element on the left and find the element while (-- j)> left & pdata [J]> middle) that is larger than middle ); // start from the first element on the right and find If (I> = J) element smaller than middle // when I is less than J, the break of the two elements is exchanged; temp = pdata [I]; pdata [I] = pdata [J]; pdata [J] = temp;} // The meaning of the following two sentences: pdata [left] And pdata [J, in this way, an array centered on pdata [J] is formed. The element with a subscript smaller than // J is smaller than pdata [J], and the element with a subscript greater than J is larger than pdata [J. Pdata [left] = pdata [J]; pdata [J] = middle; // call the recursive if (left <j) quicksort (pdata, left, J); // call recursive if (Right> I) quicksort (pdata, I, right) for the elements on the Right of pdata [J );} public static void main (string [] ARGs) {int [] pdata = new int [10]; for (INT I = 0; I <10; I ++) pdata [I] = (INT) (math. random () * 100); For (INT I = 0; I <pdata. length; I ++) system. out. print (pdata [I] + ""); qsort. quicksort (pdata, 0, pdata. length); system. out. println ("\ n ***********************"); For (INT I = 0; I <pdata. length; I ++) system. out. print (pdata [I] + "");}}

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.