zoukankan      html  css  js  c++  java
  • C#排序算法(1) 选择排序

    1. using System;    
    2.   
    3. namespace SelectionSorter    
    4. {    
    5.     public class SelectionSorter    
    6.     {    
    7.         private int min;    
    8.         public void Sort(int [] list)   
    9.         {    
    10.             forint i=0;i<list.Length-1;i++)    
    11.             {    
    12.                 min=i;    
    13.                 forint j=i+1;j<list.Length;j++)    
    14.                 {    
    15.                     if(list[j]<list[min])    
    16.                     min=j;    
    17.                 }    
    18.                 int t=list[min];    
    19.                 list[min]=list[i];    
    20.                 list[i]=t;    
    21.             }    
    22.         }    
    23.     }    
    24.   
    25.     public class MainClass    
    26.     {    
    27.         public static void Main()   
    28.         {    
    29.             int[] iArrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47};    
    30.             SelectionSorter ss=new SelectionSorter();    
    31.             ss.Sort(iArrary);    
    32.             forint m=0;m<iArrary.Length;m++)    
    33.             {   
    34.                 Console.Write("{0} ",iArrary[m]);    
    35.                 Console.WriteLine();    
    36.             }    
    37.         }    
    38.     }    
    39. }  
     
  • 相关阅读:
    关于网购心态
    c++ In STL maps, is it better to use map::insert than []? Stack Overflow
    小工具:sshcopyid_老王的技术手册 ( 我的新博客:http://huoding.com )_百度空间
    djangoqbe
    C++ STL map的使用
    容器find_if函数定义和其第三个参数重载的疑问
    ArchLinux的安装与配置
    使用Grub进行Linux的硬盘安装与修复
    MySQL数据类型简介
    ArchLinux下Alsa的简单配置
  • 原文地址:https://www.cnblogs.com/encounter/p/2188849.html
Copyright © 2011-2022 走看看