【发布时间】:2011-02-01 13:36:43
【问题描述】:
更新:好的,我知道这是一种冒泡排序,但它是否效率较低,因为它在特定运行中没有交换时不会停止?它一直运行到 first 为 null。
嗨,我有一个排序算法如下。我的问题是,这是哪种排序算法?我认为这是冒泡排序,但它不会多次运行。任何想法? 谢谢!
//sorting in descending order
struct node
{
int value;
node* NEXT;
}
//Assume HEAD pointer denotes the first element in the //linked list
// only change the values…don’t have to change the //pointers
Sort( Node *Head)
{
node* first,second,temp;
first= Head;
while(first!=null)
{
second=first->NEXT;
while(second!=null)
{
if(first->value < second->value)
{
temp = new node();
temp->value=first->value;
first->value=second->value;
second->value=temp->value;
delete temp;
}
second=second->NEXT;
}
first=first->NEXT;
}
}
【问题讨论】:
-
有一对嵌套的while循环;这将进行多次运行。