[原创]冒泡排序BubbleSort
2007-08-12 11:49 Virus-BeautyCode 阅读(528) 评论(6) 编辑 收藏 举报 public class BubbleSort
{
private int [] mylist;
public BubbleSort()
{
mylist = new int[12] { 19, 13, 5, 27, 1, 26, 31, 16, 2, 9, 11, 21 };
}
public void Pad()
{
}
public void StartSort()
{
int temp = 0;
int f = mylist.Length-1;
for (int i = 0; i < f; i++)
{
int k = 0;
for (int j = k; j < f - k; j++)
{
if (mylist[j] > mylist[j + 1])
{
temp = mylist[j];
mylist[j] = mylist[j + 1];
mylist[j + 1] = temp;
}
}
}
}
public void Display()
{
for (int i = 0; i < mylist.Length; i++)
{
Console.WriteLine(mylist[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
BubbleSort bb = new BubbleSort();
bb.StartSort();
bb.Display();
Console.ReadLine();
}
}