C # algorithm-select sorting

Source: Internet
Author: User
Code
Using System;
Using System. Collections. Generic;
Using System. text;

Namespace Sortalgorithm
{
Class Selectionsort
{
Private   Static   Int Min;
Public   Static   Void Sort ( Int [] Data)
{
For ( Int I =   0 ; I < Data. Length -   1 ; I ++ )
{
Min = I;
For ( Int J = I +   1 ; J < Data. length; j ++ )
{
If (Data [J] < Data [Min])
Min = J;
}
Int T = Data [Min];
Data [Min] = Data [I];
Data [I] = T;
}
}
Static   Void Main2 ()
{
Int [] = { 10 , 1 , 2 , 12 , 34 , 23 , 56 , 67 , 4 , 11 }; // The basic idea is: in the first round of comparison, the minimum number is obtained first, and the realization is that the two numbers are switched by position.
Selectionsort. Sort ();
For ( Int M =   0 ; M < A. length; m ++ )
Console. Write ( " {0} " , A [m]);
Console. Read ();
}
}
}

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.