我正在研究链表的冒泡排序算法。它正在移动数据,但并没有完全正确地对数据进行排序。现在我只担心整数的链表。问题出在哪里?非常感谢。
void List::linkedListBubbleSort()
{
bool swap = true;
Node * temp = firstNode;
Node * current;
if(firstNode == 0)
{
cout << "List is empty." << endl;
return;
}
else
{
while(swap == true)
{
for(current = firstNode; current != NULL && current->next != NULL; current = current->next)
{
if(current->data > current->next->data)
{
swap = true;
temp->data = current->data;
current->data = current->next->data;
current->next->data = temp->data;
}
else
swap = false;
}
}