Select the Java implementation of the sorting algorithm.

Source: Internet
Author: User
Package utils.sort; /** * @author Tony Deng * Sorting by using the selection sort method, the elements in the array must implement the comparable interface. * * Public class Choosesort implements Sortstrategy {      /**     & nbsp;  * The elements in the array obj are sorted by selecting the sorting algorithm       /*        public void sort (comparable[] obj)        {               if (obj = null)                {                      throw new NullPointerException ("The argument can not be null!");              }                    comparable tmp = NULL;               int index = 0;                 for (int i = 0; i < obj.length-1 i++)           &nbs p;   {                      index = i;                       tmp = Obj[i];                           for (int j = i + 1; j < Obj.length; J + +)         &nbs p;            {                             //Comparison of adjacent elements, ifBehind the small, just write down its location                              if (Tmp.compareto (obj[j]) > 0)                               {                                     tmp = obj[j];  //To record the current small value for each comparison!                                     index = j;                            &nBsp }                      }                        //Switching the smallest elements to the front                       tmp = Obj[i];                       Obj[i] = Obj[index];                       Obj[index] = tmp;              }        }}  

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.