Select Sort "Code"

Source: Internet
Author: User

Ideas for reference:

Http://www.cnblogs.com/kkun/archive/2011/11/23/2260281.html

The code is as follows:

`1 //171028 Select Sort. cpp: The entry point that defines the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <random>7 8 using namespacestd;9 Ten voidSelection_sort (unsignedintA[],intLen//sort in ascending order One { A     intK =0; -     intSwap =0; -      for(inti =0; I < Len-1; i++)//How many times? the     { -K =i; -          for(intj = i +1; J < Len; J + +)//each time the smallest number is selected -         { +K = (A[k] > A[j])? J:k;//if sorted in descending order, change here to A[k] < A[j] -         } +         //Exchange ASwap =A[i]; atA[i] =A[k]; -A[K] =swap; -     } -cout <<"sequence of arrays after sorting:"; -      for(inti =0; i < Len; i++) -     { incout << A[i] <<ends; -     } tocout <<Endl; + } -  the intMain () * { \$     /*default_random_engine E;Panax Notoginseng uniform_int_distribution<unsigned> U (0, +);*/ -Unsignedinttest[9] = {1,4,6,9,7,2,8,5,3 }; the     /*for (int i = 0; i < i++) +     { A Test[i] = u (e); the     }*/ +cout <<"sequence of arrays before sorting:"; -      for(auto c:test) \$cout << C <<ends; \$cout <<Endl; -Selection_sort (Test,sizeof(test)/sizeof(test[0])); -     return 0; the}`

Select Sort "Code"

Related Keywords:

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.