Selection and sequencing of data structure learning

Source: Internet
Author: User

1. Direct Select sort:

First:

To tell the truth, the direct selection of the most similar to the sort of human instinct, such as the size of toys to the three-year-old child on the size of a sequence,

The child will first find the smallest of the toys in the first place, then find the second one, and so on.

The first step: we take 80 as a reference (base), find a minimum number of 20 after 80, and then swap 80 with 20.

Step two: The first digit is already the smallest number, and then we push further after 30 to find a minimum number, find themselves the smallest without swapping.

Step Three: ...

The program source code is:

1  Packagecom.swust. Select sort;2 Importcom.swust.utils.ArrayUtils;3 4  Public classExample1 {5      Public Static voidMain (string[] args) {6         int[] arr = Arrayutils.createarray (10);7 sort (arr);8 Arrayutils.showarray (arr);9     }Ten     Private Static voidSortint[] arr) { One         //number of times to traverse A          for(inti=0;i<arr.length-1;i++){ -             //first assume that the position of the smallest element is I -             intsmall =i; the              for(intj=i;j<arr.length;j++){ -                 //find the true minimum element, and replace the subscript that assumes the smallest element with the true minimum element -                 if(arr[small]>Arr[j]) { -Small=J; +                 } -             } +             //swap the true minimum element with the assumed minimum element position A             inttemp =Arr[small]; atArr[small] =Arr[i]; -arr[i]=temp; -         }     -     } -}

Selection and sequencing of data structure learning

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.