void BubbleSort(struct lnode *head)
{
struct lnode *f, *p, *x, *y;
f = NULL;
//判断是否只有一个元素或者没有元素
if(head -> next == NULL || head -> next -> next == NULL)
{
return;
}
while(f != head->next->next)
{
//外层是N - 1次循环,升序
for(p = head; p -> next -> next != f; p = p -> next)
{
if(p -> next -> data > p -> next -> next ->data)
{
x = p -> next;
y = p -> next -> next;
p -> next = y;
x -> next = y -> next;
y -> next = x;
}
}
f = p -> next;
}
}
{
struct lnode *f, *p, *x, *y;
f = NULL;
//判断是否只有一个元素或者没有元素
if(head -> next == NULL || head -> next -> next == NULL)
{
return;
}
while(f != head->next->next)
{
//外层是N - 1次循环,升序
for(p = head; p -> next -> next != f; p = p -> next)
{
if(p -> next -> data > p -> next -> next ->data)
{
x = p -> next;
y = p -> next -> next;
p -> next = y;
x -> next = y -> next;
y -> next = x;
}
}
f = p -> next;
}
}