#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct Node
{
ElemType data;
struct Node *next;
} Node, *Linklist;
Linklist newlist()
{
Node *L, *r, *p;
ElemType x;
L = (Linklist)malloc(sizeof(Node));
L->next = NULL;
r = L;
while (scanf("%d", &x) != EOF)
{
p = (Linklist)malloc(sizeof(Node));
p->data = x;
r->next = p;
r = p;
}
r->next = NULL;
return L;
}
Linklist Operationlist(Linklist La, Linklist Lb, int i)
{
Node *pa, *qa, *pb, *qb;
int cnt;
pa = La->next;
pb = Lb->next;
cnt = 1;
while (pa != NULL && cnt < i - 1)
{
pa = pa->next;
++cnt;
}
if (pa == NULL || cnt > i - 1)
{
printf("LA delete wrong place\n");
return Lb;
}
qb=pb;
while (pb->next != NULL )
{
pb = pb->next;
}
pb->next = pa->next;
pa->next = qb;
return La;
}
int main()
{
Node *la, *lb, *p;
int i, m, j;
printf("input LA data: \n");
la = newlist();
printf("input LB data: \n");
lb = newlist();
printf("input LA delete place : \n");
scanf("%d", &i);
Operationlist(la, lb, i);
printf("LA:\n");
for (p = la->next; p != NULL; p = p->next)
printf("%d ",p->data);
printf("\n");
free(la);
free(lb);
return 0;
}
数据结构_将一整段链表插入另一链表
最新推荐文章于 2019-11-05 19:41:31 发布