Algorithm-Sort-Direct Selection and sorting (Straight Selection Sort)

Source: Internet
Author: User

 

Void SelectSort (SeqList R)
{
Int I, j, k;
For (I = 1; I <n; I ++)
{
// Perform the I-th sorting (1 ≤ I ≤ N-1)
K = I;
For (j = I + 1; j <= n; j ++) // select the smallest key in the current unordered zone R [I. n]

Record R [k]
{
If (R [j]. key <R [k]. key)
{
K = j; // k. Write down the location of the currently found minimum keyword.
}
}
If (k! = I)
{
// Exchange R [I] and R [k]
R [temp] = R [I];
R [I] = R [k];
R [k] = R [temp]; // R [temp] as a temporary storage unit
} // Endif
} // Endfor
} // SeleetSort

Void SelectSort (int [] x)
{
For (int I = 0; I <x. Length-1; I ++)
{
// Just perform n-1 cycles
Int min = I;
For (int j = I + 1; j <x. Length; j ++)
{
If (x [j] <x [min])
{
Min = j;
}
}
If (min! = I)
{
// Exchange x [I] and x [k]
Int temp;
Temp = x [I];
X [I] = x [min];
X [min] = temp;
} // Endif
} // Endfor
} // SelectSort

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.