博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#的几种算法(一)

Posted on 2006-07-07 10:08  Csunny  阅读(305)  评论(0)    收藏  举报
    
 
/* 朋友们,我最近加紧写C#的一些算法。选择排序已经推出的。现推出插入算法。 
  对想提高C#语言编程能力的朋友,我们可以互相探讨一下。 
  如:下面的程序,并没有实现多态,来,帮它实现一下。
*/
 
  
using System; 
  
public class InsertionSorter 
  

   
public void Sort(int [] list) 
   

   
for(int i=1;i<list.Length;++i) 
   

   
int t=list[i]; 
   
int j=i; 
   
while((j>0)&&(list[j-1]>t)) 
   

   list[j]
=list[j-1]; 
   
--j; 
   }
 
   list[j]
=t; 
   }
 
   
   }
 
  }
 
  
public class MainClass 
  

   
public static void Main() 
   

   
int[] iArrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47}
   InsertionSorter ii
=new InsertionSorter(); 
   ii.Sort(iArrary); 
   
for(int m=0;m<=13;m++
   Console.WriteLine(
"{0}",iArrary[m]); 
   }
 
  }
 
  
//已经编译运行通过.这太简单了,我不做详细介绍了.