• C#排序算法 之 冒泡排序


    1. using System;   
    2.   
    3. namespace BubbleSorter    
    4. {    
    5.     public class BubbleSorter    
    6.     {    
    7.         public void Sort(int [] list)    
    8.         {    
    9.             int i,j,temp;    
    10.             bool done=false;    
    11.             j=1;    
    12.             while((j<list.Length)&&(!done))    
    13.             {    
    14.                 done=true;    
    15.                 for(i=0;i<list.Length-j;i++)    
    16.                 {    
    17.                     if(list[i]>list[i+1])    
    18.                     {    
    19.                         done=false;    
    20.                         temp=list[i];    
    21.                         list[i]=list[i+1];    
    22.                         list[i+1]=temp;    
    23.                     }    
    24.                 }    
    25.                 j++;    
    26.             }    
    27.         }    
    28.     }    
    29.   
    30.     public class MainClass    
    31.     {    
    32.         public static void Main()    
    33.         {    
    34.             int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};    
    35.             BubbleSorter sh=new BubbleSorter();    
    36.             sh.Sort(iArrary);    
    37.             forint m=0;m<iArrary.Length;m++)    
    38.             {   
    39.                 Console.Write("{0} ",iArrary[m]);    
    40.                 Console.WriteLine();    
    41.             }   
    42.         }    
    43.     }    
    44. } 
  • 相关阅读:
    C#后台正则表达式
    Layer 弹出层抖动问题
    JS中子页面父页面方法 变量相互调用
    layer最大话.最小化.还原回调方法
    trove远程连接mongodb
    tar.gz tar.bz2的解压命令
    IO测试工具之fio详解
    HTTP请求方法
    jmeter --使用put方法上传文件
    DHCP的原理和实现过程
  • 原文地址:https://www.cnblogs.com/encounter/p/2188848.html
Copyright © 2020-2023  润新知