/*单链表L=a1,b1,a2,b2,a3,b3,拆分成L=a1,a2,a3,L2=b3,b2,b1*/
void split(LinkNode*& L, LinkNode*& L1, LinkNode*& L2)
{
LinkNode* p, * q, * r;
p = L->next;
L1 = L;
r = L1;
L2 = (LinkNode*)malloc(sizeof(ElemType));
L2->next = NULL;
while (p != NULL)
{
r->next = p;
r = p;
p = p->next;
q = NULL;
if (p != NULL)
{
q = p->next;
p->next = L2->next;
L2->next = p;
}
}
r->next = NULL;
}
删除单链表L中元素最大节点
void delmaxnode(LinkNode*& L) { LinkNode* p, * pre, * max_p, * max_pre; pre = L; p = L->next; max_pre = pre; max_p = p; while (p != NULL) { if (p->data > max_p->data) { max_p = p; max_pre = pre; } pre = pre->next; p = p->next; } max_pre->next = max_p->next; free(max_p); }
元素递增有序排列
void sort(LinkNode*& L)
{
LinkNode* p, * q, * pre;
p = L->next->next;
L->next->next = NULL;
while (p != NULL)
{
pre = L;
q = p->next;
while (pre->next != NULL && pre->next->data < p->data)
{
pre=pre->next;
}
p->next = pre->next;
pre->next = p;
p = q;
}
}