Java Sorting algorithm--Quick sort

Source: Internet
Author: User

Import java.util.arrays;//=================================================//File name:arrays_quick//----------- -------------------------------------------------------------------//author:common//class Name: arrays_quick//property://Method: C Lass arrays_quick{private int[] arrays;private int curnum;public arrays_quick (int max) {//Create an empty array of Max lengths super (); Arrays = New int[max];curnum = 0;} public void Insert (int value) {//empty array add element arrays[curnum] = value;curnum++;} public void display () {//display array System.out.println (arrays.tostring (Arrays));} public void QuickSort () {int I=0;int j=arrays.length-1;recquicksort (i, j);}                 public void Recquicksort (int i,int j) {//End condition if (i = = j) return;        int key = Arrays[i]; int Stepi = i; Record start position int STEPJ = j;                 Record End Position while (J > i) {//J <<--------------Forward lookup if (Arrays[j] >= key) {            j--;                }else{Arrays[i] = arrays[j]; i++------------>> Backward Lookup while (J > ++i) {if (Arrays[i] > key) {                        ARRAYS[J] = arrays[i];                    Break }}}}//If the first key taken is the smallest number if (Stepi = = i) {Recquicksort (            ++i, STEPJ);        Return                 }//Last vacancy left for key arrays[i] = key;        Recursive Recquicksort (Stepi, i);    Recquicksort (J, STEPJ); }}//main class//function:quicksortpublic class QuickSort {public static void main (string[] args) {//TODO auto-generated method stub I NT MaxSize = 5; Arrays_quick Arrays_demo = new Arrays_quick (maxSize); Arrays_demo.insert (4); Arrays_demo.insert (5); Arrays_ Demo.insert (3); Arrays_demo.insert (1); Arrays_demo.insert (2); Arrays_demo.display (); Arrays_demo. QuickSort (); Arrays_demo.display ();}}

Java Sorting algorithm--Quick sort

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.