zoukankan      html  css  js  c++  java
  • 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. } 
  • 相关阅读:
    2018.11.21 struts2获得servletAPI方式及如何获得参数
    2018.11.20 Struts2中对结果处理方式分析&struts2内置的方式底层源码剖析
    2018.11.19 Struts2中Action类的书写方式
    2018.11.18 Sturts2配置详解&常量配置进阶
    2018.11.17 Struts2框架入门
    需求分析
    可行性研究
    防火墙
    homework1
    静态网页开发技术
  • 原文地址:https://www.cnblogs.com/encounter/p/2188848.html
Copyright © 2011-2022 走看看