C#算法之选择排序浅析

开发 后端 算法
C#选择排序是什么呢?C#选择排序是如何实现的呢?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#算法有所帮助。

【编辑推荐】

  1. 浅析C#调用ImageAnimator
  2. C#连接Access、SQL Server数据库
  3. 浅谈C#固定的和活动的变量
  4. 介绍C#中的值类型
  5. C#算法巧解八皇后问题浅析
责任编辑:仲衡 来源: 酷网学院
相关推荐

2021-01-19 07:02:26

算法数据结构堆排序

2009-08-25 17:59:49

C#入门

2009-08-11 14:51:11

C#数据结构与算法

2009-08-11 14:43:42

C#数据结构与算法

2009-08-11 13:54:54

约瑟夫环算法C#算法

2009-08-11 14:30:32

C#数据结构与算法

2009-08-20 10:25:37

C#操作内存

2009-08-11 14:14:42

C#数据结构与算法

2023-10-09 07:11:03

排序算法序列

2009-08-25 17:41:51

C#开发排序算法

2009-08-19 17:20:22

C# 操作符

2009-08-19 15:47:09

C#操作Access

2009-08-18 14:25:05

C# 操作Excel

2009-09-18 19:21:17

C#接口

2009-08-18 16:42:49

C# 操作XML

2009-08-19 15:55:42

C#操作Access

2009-08-11 09:16:00

2009-08-11 10:26:49

C#算法C#字符串反转

2009-08-07 17:25:37

C# SortedLi

2009-08-17 18:34:50

C# ChangeCo
点赞
收藏

51CTO技术栈公众号