链表排序求教!
请问各位高人单链表如何交换两个结点??? (不是交换结点的信息data)
搞了半天,就是不完全,怎样考虑的周到点?
请教一下,怎么完善啊?
LinkList p = *L,q = p->next,r = NULL,s = NULL;
if(q->next == NULL) {return (1);}
while(q != NULL && q->data < 0) {p = p->next; q = p->next;}
r = q;
s = r->next;
while(s != NULL)
{
if(s->data < 0)
{
p->next = q->next;
r->next = s->next;
s->next = p->next;
p->next = s;
q->next = r->next;
r->next = q;
p = p->next;
q = p->next;
}
r = r->next;
s = r->next;
}