[1] algorithm path-select sorting

Source: Internet
Author: User

Select sort-Algorithm

1. Split objects to be sorted2Partially, one is sorted, and the other is unordered.

2. Select a minimum value from the unordered part of the backend and put it to the last one in the sorted part of the front end.

E. g:

Before sorting: 70 80 31 37 10 1 48 60 33 80


[1] 80 31 37 10 7048 60 33 80 select minimum value 1

[1 10] 31 37 80 7048 60 33 80 selected minimum 10

[1 10 31] 37 80 7048 60 33 80 selected minimum value 31

[1 10 31 33] 80 7048 60 37 80 ......

[1 10 31 33 37] 7048 60 80 80 ......

[1 10 31 33 37 48] 70 60 80 80 ......

[1 10 31 33 37 4860] 70 80 80 ......

[1 10 31 33 37 4860 70] 80 80 ......

[1 10 31 33 37 4860 70 80] 80 ......


 
# Define swaper (x, y) {int t; t = x; X = y; y = T;} select sort-program segment: int selectionsort (int A [], int lens) {int I, j, k; for (I = 0; I <lens; I ++) {int minindex = I; for (j = I + 1; j <lens; j ++) {if (a [minindex]> A [J]) {minindex = J ;}} if (I! = Minindex) swaper (A [I], a [minindex]);} return 0;} int selectionsort2 (int A [], int lens) {int I, J, K; for (I = 0; I <lens; I ++) {for (j = I + 1; j <lens; j ++) {if (a [I] <A [J]) {swaper (A [I], a [J]) ;}} return 0 ;}


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.