|
mycs
- 论坛元老
- 3583
- 368
-
2009-02-07
|
mycs
2009-02-11 22:28
|只看楼主
1#
t
T
冒泡排序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>list[i+1]) { done=false; temp=list; list=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(); } } }
| 选择排序using System;
namespace SelectionSorter { public class SelectionSorter { private int min; public void Sort(int [] list) { for(int i=0;i<list.Length-1;i++) { min=i; for(int j=i+1;j<list.Length;j++) { if(list[j]<list[min]) min=j; } int t=list[min]; list[min]=list; list=t; } } } public class MainClass { public static void Main() { int[] iArrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47}; SelectionSorter ss=new SelectionSorter(); ss.Sort(iArrary); for(int m=0;m<iArrary.Length;m++) Console.Write("{0} ",iArrary[m]); Console.WriteLine(); } } } |
本主题由 管理员 admin 于 2009-2-11 23:23:16 执行 设置精华/取消 操作
|