C # Select Sort

Source: Internet
Author: User
C # Select Sort

Using System;  Using System.Collections.Generic;  Using System.Linq;  Using System.Text; Namespace sort {Class Selectsorter {public static int[] Sort (int[] a) {Select              Sort (a);          return A;              } private static void Selectsort (int[] myArray) {int I, j, smallest; Data starting position, from 0 to penultimate data for (i = 0; i < myarray.length-1; i++) {smallest = i;// Minimum data is recorded for (j = i + 1; j < Myarray.length; J + +) {//In the remaining data to find the most Small data if (Myarray[j] < myarray[smallest]) {smallest = j;//as The result is smaller than it, record subscript}}//To swap the smallest data and unsorted First Data swap (ref Myarray[i],              Ref myarray[smallest]); }} private static void Swap (ref int left, ref int. right) {int Temp              temp = left;              left = right;          right = temp; }      }  }

Choose the idea of sorting:


Example:

The above is the C # selection sort of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.