Quick ordering of sorting algorithms (Java Implementation)

Source: Internet
Author: User

Package com.javatest300;

public class Test039 {

public static void Main (string[] args) {//Quick sort

int a[]={2,3,8,10,5,1,8,78,35,12};

SYSTEM.OUT.PRINTLN ("---------before sorting");

for (int i = 0; i < a.length; i++) {

System.out.print (a[i]+ "");

}

System.out.println ();

SYSTEM.OUT.PRINTLN ("---------after sorting");

Quick_sort (A, 0, a.length-1);

for (int i = 0; i < a.length; i++) {

System.out.print (a[i]+ "");

}

System.out.println ();

}

public static void Quick_sort (int arr[],int start,int end) {

if (start<end) {//The case of course omitted (ARR==NULLEND-START+1<2), that is, the passed array is empty and only one element in the array

int privote=partition (arr,start,end);

Quick_sort (arr, start, privote-1);

Quick_sort (arr, privote+1, end);

}

}

public static int Partition (int. arr[],int Low,int High) {

int Tmp=arr[low];

while (Low

while (Low

high--;

}

Arr[low]=arr[high];

while (low

low++;

}

Arr[high]=arr[low];

}

arr[low]=tmp; return low;

}

}

Quick ordering of sorting algorithms (Java Implementation)

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.