Algorithm-sort-select sort

Source: Internet
Author: User

A long time no review algorithm, and today began to take to practice practiced hand.

Start with a simple sort of selection.

Select Sort, that is, in order, each time starting from a certain number, select a minimum (large) number to swap the position with a number.

  

1 /*2 * Copyright (c)4 * All rights reserved.5  */6  Packagesort;7 /**8 * Description: Select sorting algorithm9 * <p/>Ten * <br><br>time:2015-11-3 pm 4:58:05 One  * A  * @authorZXL -  * @version1.0 -  * @since1.0 the  */ -  Public classSelectionsort { -      Public Static voidMain (string[] args) { -         int[] nums= {4,8,7,5,8,5,9,3,2,1}; + selectionsort.selection (nums); -          for(inte:nums) { +System.out.print (e+ ","); A         } at     } -      -      Public Static voidSelectionint[] nums) { -         inttemp = 0; -         intMark = 0;//location to mark the minimum number -          for(inti=0; i<nums.length; i++){ in             //each time starting with a certain number -             intMin =Nums[i]; to             //Next to the size of the number in the back, find the minimum number +              for(intJ=i; j<nums.length; J + +){ -                 if(min>Nums[j]) { theMin =Nums[j]; *Mark =J; $                 }Panax Notoginseng             } -             //swap positions with thetemp =Nums[i]; +Nums[i] =Nums[mark]; ANums[mark] =temp; the         } +     } -}

Algorithm-sort-select 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.