Data Structure-selection and sorting using C language

Source: Internet
Author: User

Data Structure-selection and sorting using C language

Version 1: update immediately. Please wait ...... version 2: // select sorting // first set the 0 position as the index, and then use the index to find the smallest value. // put the smallest value in front of each row, then exchange the data with the original data location // Yang Xin # include

 
  
# Include

  
   
# Define MAXN 100int arr [MAXN]; void SelectionSort (int a [], int size) {int index = 0, I = 0, j = 0, temp = 0; for (I = 0; I <size; I ++) {index = I; for (j = I + 1; j <size; j ++) {if (arr [index]> arr [j]) {index = j ;}} if (index! = I) {temp = arr [I]; arr [I] = arr [index]; arr [index] = temp ;}} int main () {int I = 0; arr [0] = 44; arr [1] = 33; arr [2] = 55; arr [3] = 999; arr [4] = 42; printf (====================================================== ======== ); printf (the data order before sorting is 44 33 55 999 42); SelectionSort (arr, 5); printf (the sorted Data Order is :); for (I = 0; I <5; I ++) {printf (% d, arr [I]);} printf (====================================================== ======== ); return 0 ;}

  

 

 

Result:

 

Related Article

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.