题目描述:将一个带头结点单链表 A分解为A 和 B 使得 A 中为奇数项元素,B 中为偶数项元素,保持其相对顺序不变。
void EvenAndOdd(LinkList &A){LinkList *B = (LinkList)malloc(sizeof(LNode));B->next = NULL;LNode *p = A->next;LNode *pre = A;LNode *r = B;int count = 1;while(p){if(count % 2 == 0){LNode *q = (LinkList)malloc(sizeof(LNode));q->data = p->data;pre->next = p->next;p = p->next;r->next = q;r = q; }else{pre = p;p = p->next; }count++;}r->next = NULL;
}