现在的位置: 首页 > 综合 > 正文

C#排序算法(1) 选择排序

2013年03月12日 ⁄ 综合 ⁄ 共 1004字 ⁄ 字号 评论关闭
  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. }  

 

抱歉!评论已关闭.