Select sort directly select sort, select sort

Source: Internet
Author: User

Select sort directly select sort, select sort

Today, Dapeng learned how to directly select the sorting method in sorting.

Straight SelectSort is also a simple sorting method. Its basic idea is to first select the minimum value from R [0]-R [n-1, exchange with R [0], select the minimum value from R [1]-R [n-1] For the second time, and exchange with R [1 ,... A total of N-1 exchanges are used to obtain an ordered sequence of sorted codes in ascending order.

The Java implementation code is as follows:

 

Public classStraightSelectSort {

 

Public static voidMain (String [] args ){

//TODOAuto-generatedmethod stub

Int[] A = };

IntI, j, index;

System.Out. Print ("Before sorting :");

For(IntX: ){

System.Out. Print (x + ",");

}

For(I = 0; I <a. length; I ++ ){

Index = I;

For(J = I + 1; j <a. length; j ++ ){

If(A [j] <a [index])

Index = j;

If(I! = Index ){

IntTmp = a [I];

A [I] = a [index];

A [index] = tmp;

}

}

}

System.Out. Print ("sorted :");

For(IntX: ){

System.Out. Print (x + ",");

}

}

 

}

Regardless of the initial status of the sequence, n-I comparisons are required to select the maximum and minimum keyword records in the I-th sorting. Therefore, the total number of comparisons is n (n-1) /2 = O (n ^ 2 ).

 


What is the difference between simple selection sorting and Direct selection sorting?

It is called differently. In fact, the two are exactly the same.

Directly select sort C language (Supplement directly select sort)

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.