Implement quick sorting using Java generics

Source: Internet
Author: User
Package ch10; public class quicksort {/*** successfully-quick sorting * adopts generic-natural sorting * @ Param <t> * @ Param T */public static <t extends comparable> void quiksort (T [] T) {recursivesort (T, 0, T. length-1 );} /*** Quick Sort-recursive call * @ Param <t> * @ Param T * @ Param low * @ Param high */Private Static <t extends comparable> void recursivesort (T [] t, int low, int high) {If (t = NULL | low> = high) return; int partial tloc = partition (T, low, high ); // sort the sub-sequences with shorter lengths first to reduce the maximum stack depth to O (logn) if (pivotloc-low> high-latency tloc) in the worst case) {recursivesort (T, effectloc + 1, high); recursivesort (T, low, pivotLoc-1);} else {recursivesort (T, low, pivotLoc-1); recursivesort (t, required tloc + 1, high );}} /*** quick sorting-one partition * @ Param <t> * @ Param T * @ Param low * @ Param high * @ return */Private Static <t extends comparable> int partition (T [] t, int low, int high) {selectpivotkey (T, low, high); // system. out. println ("low ---" + T [low]); t pivotkey = T [low]; while (low 

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.