成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

四種C#排序算法代碼示例

開發 后端 算法
這里將展示四種C#排序算法代碼示例,包括冒泡排序(Bubble)、選擇排序(Selection)、插入排序(InsertionSorter)等四種。
C#排序算法一般都涉及到循環,以及賦值。通過排序,能進行簡單的統計與分類,具有極其重要的價值。這里將介紹四種不同的C#排序算法代碼,希望對大家有所幫助。

C#排序算法一、冒泡排序(Bubble)

  1. using System;   
  2. namespace BubbleSorter   
  3. {   
  4. public class BubbleSorter   
  5. {   
  6. public void Sort(int[] list)   
  7. {   
  8. int i,j,temp;   
  9. bool done=false;   
  10. j=1;   
  11. while((j{   
  12. done=true;   
  13. for(i=0;i{   
  14. if(list[i]>list[i+1])   
  15. {   
  16. done=false;   
  17. temp=list[i];   
  18. list[i]=list[i+1];   
  19. list[i+1]=temp;   
  20. }   
  21. }   
  22. j++;   
  23. }   
  24. }   
  25. }   
  26.  
  27. public class MainClass   
  28. {   
  29. public static void Main()   
  30. {   
  31. int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};   
  32. BubbleSorter sh=new BubbleSorter();   
  33. sh.Sort(iArrary);   
  34. for(int m=0;mConsole.Write("{0} ",iArrary[m]);   
  35. Console.WriteLine();   
  36. }   
  37. }   
  38. }  

C#排序算法二、選擇排序(Selection)

  1. using System;   
  2. namespace SelectionSorter   
  3. {   
  4. public class SelectionSorter   
  5. {   
  6. private int min;   
  7. public void Sort(int [] list)   
  8. {   
  9. for(int i=0;i{   
  10. min=i;   
  11. for(int j=i+1;j{   
  12. if(list[j]min=j;   
  13. }   
  14. int t=list[min];   
  15. list[min]=list[i];   
  16. list[i]=t;   
  17. }   
  18. }   
  19. }   
  20.  
  21. public class MainClass   
  22. {   
  23. public static void Main()   
  24. {   
  25. int[] iArrary = new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47};   
  26. SelectionSorter ss=new SelectionSorter();   
  27. ss.Sort(iArrary);   
  28. for (int m=0;mConsole.Write("{0} ",iArrary[m]);   
  29. Console.WriteLine();   
  30. }   
  31. }   
  32. }  

C#排序算法三、插入排序(InsertionSorter)

  1. using System;   
  2. namespace InsertionSorter   
  3. {   
  4. public class InsertionSorter   
  5. {   
  6. public void Sort(int [] list)   
  7. {   
  8. for(int i=1;i{   
  9. int t=list[i];   
  10. int j=i;   
  11. while((j>0)&&(list[j-1]>t))   
  12. {   
  13. list[j]=list[j-1];   
  14. --j;   
  15. }   
  16. list[j]=t;   
  17. }   
  18. }   
  19. }   
  20.  
  21. public class MainClass   
  22. {   
  23. public static void Main()   
  24. {   
  25. int[] iArrary=new int[]{1,13,3,6,10,55,98,2,87,12,34,75,33,47};   
  26. InsertionSorter ii=new InsertionSorter();   
  27. ii.Sort(iArrary);   
  28. for(int m=0;mConsole.Write("{0}",iArrary[m]);   
  29. Console.WriteLine();   
  30. }   
  31. }   
  32. }  

C#排序算法四、希爾排序(ShellSorter)

  1. using System;   
  2.  
  3. namespace ShellSorter   
  4. {   
  5. public class ShellSorter   
  6. {   
  7. public void Sort(int [] list)   
  8. {   
  9. int inc;   
  10. for(inc=1;inc<=list.Length/9;inc=3*inc+1);   
  11. for(;inc>0;inc/=3)   
  12. {   
  13. for(int i=inc+1;i<=list.Length;i+=inc)   
  14. {   
  15. int t=list[i-1];   
  16. int j=i;   
  17. while((j>inc)&&(list[j-inc-1]>t))   
  18. {   
  19. list[j-1]=list[j-inc-1];   
  20. j-=inc;   
  21. }   
  22. list[j-1]=t;   
  23. }   
  24. }   
  25. }   
  26. }   
  27.  
  28. public class MainClass   
  29. {   
  30. public static void Main()   
  31. {   
  32. int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};   
  33. ShellSorter sh=new ShellSorter();   
  34. sh.Sort(iArrary);   
  35. for(int m=0;mConsole.Write("{0} ",iArrary[m]);   
  36. Console.WriteLine();   
  37. }   
  38. }   
  39. }  

【編輯推薦】

  1. C#委托實例簡單分析
  2. 一個.NET委托的故事:彼得,老板和宇宙
  3. 解惑答疑:C#委托和事件
  4. 各版本.NET委托的寫法回顧
  5. 換一個角度看.NET中的理解委托和事件
責任編輯:彭凡 來源: CSDN
相關推薦

2024-10-24 08:04:00

2015-03-19 15:13:20

PHP基本排序算法代碼實現

2021-06-24 17:55:40

Python 開發編程語言

2009-08-20 09:52:31

C#參數類型

2009-08-26 15:04:35

C#轉換

2009-08-05 14:09:04

C#日期轉換

2009-08-26 18:14:11

C#排序算法

2009-09-22 14:20:39

C#播放聲音

2009-09-17 16:55:58

C#組件設計

2024-06-24 01:00:00

2017-04-25 08:26:39

神經網絡解碼

2021-08-11 20:17:22

推薦算法系統

2024-06-18 08:37:25

場景異步編程代碼

2024-02-28 09:22:03

限流算法數量

2009-08-27 15:00:55

C#線程控制

2024-05-29 13:18:12

線程Thread?方式

2011-12-30 13:15:53

Java

2023-07-11 10:24:00

分布式限流算法

2023-11-15 07:40:40

2023-10-09 07:11:03

排序算法序列
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 综合国产 | 国产高清视频一区 | 国产精品视频免费观看 | 国产日韩欧美精品一区二区 | 超碰人人插 | 国产一区二区在线免费观看 | 国产精品国产精品国产专区不片 | 欧美日韩一区二区三区四区 | 天天干夜夜操视频 | 免费黄网站在线观看 | 久久国产亚洲精品 | 91在线影院 | 日韩精品在线看 | 亚洲精品日日夜夜 | 成人在线播放网站 | 国产美女永久免费无遮挡 | 国产精品高| 精久久久 | 精品成人 | 国产在线视频一区二区董小宛性色 | 亚洲国产成人精品女人久久久野战 | 亚洲欧美v | 日韩欧美在线不卡 | 国产高清视频在线观看 | 久久精品国产99国产 | 天天爽夜夜爽精品视频婷婷 | 农夫在线精品视频免费观看 | 日韩欧美一区二区三区免费观看 | 久久不卡| 中文字幕av在线播放 | 亚洲精品一区二区三区在线 | 日韩高清国产一区在线 | 狠狠久 | 久久久99国产精品免费 | 欧美精品在线一区二区三区 | av成人在线观看 | 成人精品一区二区三区 | 欧美专区在线 | www.久久 | 天天综合成人网 | 日日摸天天添天天添破 |