Posted on 2008-01-26 21:07
luofeng 阅读(109)
评论(0) 编辑 收藏 引用 所属分类:
Data Structure
冒泡排序算法:
void BubleSort(SqList &L)
{
bool exchange;
for (int i=2; i<=n; i++)
{
exchange = false;
for (int j=1; j<=n-i+1; j++)
{
if (L.r[j].key>L.r[j+1].key)
{
exchange = true;
L.r[0] = L.r[j+1];
L.r[j+1] = L.r[j];
L.r[j] = L.r[0];
}
}
if (!exchange)
{
return;
}
}
}