Java algorithm interview question: What are the various methods of sorting? Please list. Implement a quick sort with java. Select at least 4 ways to sort the bubbling quick set

Source: Internet
Author: User

 PackageCom.swift;Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.Comparator;Importjava.util.List; Public classQuickSort {/** Quick Sort*/         Public Static voidMain (string[] args) {string[] strvoid=NewString[] {"11", "66", "22", "0", "55", "22", "0", "32"}; QuickSort Sort=NewQuickSort (); Sort.quicksort (Strvoid,0, Strvoid.length-1);  for(inti = 0; i < strvoid.length; i++) {System.out.println (Strvoid[i]+ " "); }        //Sort by ComparatorList<string> list=NewArraylist<string>();  for(String str:strvoid) {list.add (str); } collections.sort (List,NewComparator<string>() {@Override Public intCompare (String arg0, String arg1) {intnum=Arg1.compareto (arg0); returnnum;        }                    });  for(String str:list) {System.out.print (str+" | "); }    }         Public voidQuickSort (string[] strdate,intLeftintRight )        {String middle, tempdate; intI, J; I=Left ; J=Right ; Middle= strdate[(i + j)/2];  Do {             while(Strdate[i].compareto (middle) < 0 && I <Right ) I++;//find the number that is larger than the middle value on the left             while(Strdate[j].compareto (middle) > 0 && J >Left ) J--;//find the number that is lower on the right than the middle value            if(I <= J) {//Replace the large number on the left and the small number on the rightTempdate =Strdate[i]; Strdate[i]=Strdate[j]; STRDATE[J]=tempdate; I++; J--; }        }  while(i <= J);//stop when the two are staggered        if(I <Right ) {QuickSort (strdate, I, right);//from        }        if(J >Left )        {QuickSort (Strdate, left, J); }    }}

Java algorithm interview question: What are the various methods of sorting? Please list. Implement a quick sort with java. Select at least 4 ways to sort the bubbling quick set

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.