赞
踩
- /*create by tyy*/
-
- #include <iostream>
- #include <string>
- using namespace std;
- #define ok 1
- #define error -1
- #define overflow -2
-
- typedef int status;
- typedef int ElemType;
- typedef struct LNode {
- ElemType data;
- LNode *next;
- }LNode, *LinkList;
-
-
- //1.将两个递增有序链表合并成一个有序的递增链表,不占用其他的空间,表中无重复数据
- status mergeList(LinkList &la, LinkList &lb, LinkList &lc) {
- LinkList pa, pb, pc;
- pa = la->next;
- pb = lb->next;
- lc = pc = la;
- while (pa&&pb) {
- if (pa->data < pb->data) {
- pc->next = pa;
- pc = pa;
- pa = pa->next;
- }
- else if (pa->data > pb->data) {
- pc->next = pb;
- pc = pb;
- pb = pb->next;
- }
- else { //pa->data==pb->data
- pc->next = pa;
- pc = pa;
- pa = pa->next;
- pb = pb->next;
- }
- }
- pc->next = pa ? pa : pb;
- delete lb;
- return ok;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。