Quick Sort (Java edition)

Source: Internet
Author: User

package com.love.test;import java.util.Scanner;/** * @author Huowolf * Quick Sort Implementation * Fast-line is a very good sorting algorithm. * Core: Divide and conquer Law (1. Select Primitives 2. Partitions 3. Recursive child columns) */public class QuickSort {public static void QuickSort (int[] arr,int start, int end) {if (start< ; end) {int I=start, j=end, x=arr[start];//Primitive while (i<j) {//right-to-left scan less than X number while (I<j && arr[j]>=x) j--;if (i <J) arr[i++]=arr[j];//scan from left to right for numbers greater than x while (I<j && arr[i]<=x) i++;if (i<j) arr[j--]=arr[i];} arr[i]=x;//the base number quicksort (arr, start, end-1) in the last position;//recursive quicksort (arr, start+1, end);}} public static void Main (string[] args) {int[] arr = new int [10]; System.out.println ("Please enter 10 integers:"); Scanner s = new Scanner (system.in); for (int i=0;i<10;i++) {Arr[i] = S.nextint ();} System.out.println ("Order before sorting:"); for (int i=0;i<10;i++) {System.out.print (arr[i]+ "");} QuickSort (arr, 0, arr.length-1); System.out.println ("\ n sort order:"), for (int i=0;i<10;i++) {System.out.print (arr[i]+ "");}}} 

refer to a Daniel's blog post, very good, blog address: http://blog.csdn.net/morewindows/article/details/6684558

Come on, yourself!!

Quick Sort (Java edition)

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.