Quick sort (inside sort)

Source: Internet
Author: User

1 /**2  * 3  */4  PackageCom.trfizeng.changesort;5 6 /**7  * @authorTrfizeng Internal Sort Exchange sort-quick sort8  */9  Public classQuickSort {Ten  One     //find the location of the keyword A      Public Static intWordkey (int[] Array,intLowintHigh ) { -         intWord =Array[low]; -          while(Low <High ) { the              while(Low < High && Array[high] >=word) { -                 //The forward scan is bigger than the key, go ahead. -high--; -             } +             //Conversely, the high position to low -Array[low] =Array[high]; +  A              while(Low < High && Array[low] <=word) { at                 //scan backwards, and continue to scan backwards, smaller than the keyword -low++; -             } -             //instead, put it in high places. -Array[high] =Array[low]; -         } in         //Insert keywords into the correct location -Array[low] =Word; to         returnLow ; +     } -  the      Public Static int[] QSort (int[] Array,intLowintHigh ) { *         if(Low <High ) { $             //look for the location of the keyword, because the next time you want to determine the low and high of the child record based on the location of the keywordPanax Notoginseng             intWordkey =Quicksort.wordkey (array, low, high); -             //for low sequence recursion theQuicksort.qsort (array, Low, wordKey-1); +             //for high sequence recursion AQuicksort.qsort (Array, Wordkey + 1, high); the         } +         //Finish Sorting -         returnArray; $     } $  -      Public Static int[] QuickSort (int[] Array) { -         if(Array! =NULL&& Array.Length! = 0) { the             intLow = 0; -             intHigh = Array.length-1;Wuyi Quicksort.qsort (array, low, high); the         } -         returnArray; Wu     } -}
View Code
1  Packagecom.trfizeng.test;2 3 ImportCom.trfizeng.changesort.BubbleSort;4 ImportCom.trfizeng.changesort.QuickSort;5 ImportCom.trfizeng.insertionsort.StraightInsertionSort;6 ImportCom.trfizeng.selectionsort.SimpleSelectionSort;7 8 /**9 * Test ClassTen  *  One  * @authorTrfizeng A  *  -  */ -  Public classSorttest { the     //Array to sort -     Static int[] Array =New int[] {6, 1, 4, 10, 11, 8, 7, 1, 0 }; -  -     /** + * Direct insertion sequencing test -      */ +      Public Static voidstraightinsertionsorttest () { ASystem.out.print ("Array to sort: ["); at          for(inti = 0; i < Array.Length; i++) { -System.out.print (Array[i] + ""); -         } -System.out.print ("]"); -  -Array =Straightinsertionsort.straightinsertionsort (array); inSystem.out.print ("Sorted array: ["); -          for(inti = 0; i < Array.Length; i++) { toSystem.out.print (Array[i] + ""); +         } -System.out.print ("]"); the     } *  $     /**Panax Notoginseng * Select Sort -      */ the      Public Static voidSimpleselectionsort () { +System.out.print ("Array to sort: ["); A          for(inti = 0; i < Array.Length; i++) { theSystem.out.print (Array[i] + ""); +         } -System.out.print ("]"); $  $Array =Simpleselectionsort.simpleselectionsort (array); -System.out.print ("Sorted array: ["); -          for(inti = 0; i < Array.Length; i++) { theSystem.out.print (Array[i] + ""); -         }WuyiSystem.out.print ("]"); the     } -  Wu     /** - * Bubble Sort About      */ $      Public Static voidBubblesort () { -System.out.print ("Array to sort: ["); -          for(inti = 0; i < Array.Length; i++) { -System.out.print (Array[i] + ""); A         } +System.out.print ("]"); the  -Array =Bubblesort.bubblesort (array); $System.out.print ("Sorted array: ["); the          for(inti = 0; i < Array.Length; i++) { theSystem.out.print (Array[i] + ""); the         } theSystem.out.print ("]"); -     } in  the     /** the * Quick Sort About      */ the      Public Static voidQuickSort () { theSystem.out.print ("Array to sort: ["); the          for(inti = 0; i < Array.Length; i++) { +System.out.print (Array[i] + ""); -         } theSystem.out.print ("]");Bayi  theArray =Quicksort.quicksort (array); theSystem.out.print ("Sorted array: ["); -          for(inti = 0; i < Array.Length; i++) { -System.out.print (Array[i] + ""); the         } theSystem.out.print ("]"); the     } the  -      Public Static voidMain (string[] args) { the         //sorttest.straightinsertionsorttest (); the  the         //Sorttest.simpleselectionsort ();94  the         //Sorttest.bubblesort (); the  the Sorttest.quicksort ();98     } About}
View Code

Quick sort (inside 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.