★搜Asp.net★(www.soAsp.net),为专业技术文档网站。
包括Asp.net开发技术文档·C#开发技术文档·Access/SQL Server数据库开发技术文档·VB.NET开发技术文档。
还包括·项目实战经验总结·开发经验技巧总结·项目开发心得。
数据结构_C#实现冒泡排序

冒泡排序

using System;
namespace BubbleSorter 

{   public class BubbleSorter 

{   public void Sort(int [] list) 

{   int i,j,temp; 

bool done=false; 

j=1; 

while((j<list.Length)&&(!done)) 

{ done=true; 

for(i=0;i<list.Length-j;i++) 



if(list[i]>list[i+1]) 



done=false; 

temp=list[i]; 

list[i]=list[i+1]; 

list[i+1]=temp; 

}   } 

j++;  }    

}   } 
public class MainClass 

{   public static void Main() 



int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47}; 

BubbleSorter sh=new BubbleSorter(); 

sh.Sort(iArrary); 

for(int m=0;m<iArrary.Length;m++) 

Console.Write("{0} ",iArrary[m]); 

Console.WriteLine(); 

}  }