C#算法之选择排序浅析 - Go语言中文社区

C#算法之选择排序浅析


C#选择排序算法是什么呢?是如何实现的呢?希望通过介绍能为C#算法的学习者带来一些益处。学语言要花大力气学数据结构和算法。

以下就是C#选择排序的实现方法:

  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. Console.Write("{0} ",iArrary[m]);   
  34. Console.WriteLine();   
  35.  
  36. }   
  37. }   

C#选择排序的介绍就到这里,赶紧动手试试吧,希望对你学习C#算法有所帮助。

版权声明:本文来源51CTO,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:http://developer.51cto.com/art/200908/143124.htm
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-05-16 04:19:39
  • 阅读 ( 1159 )
  • 分类:算法

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢