两个链表合并算法

来源:互联网 发布:小知科技 alex 编辑:程序博客网 时间:2024/05/16 10:34

A - * - * -*

B - * - * -*

将 A 指向B的第一个结点 B的尾结点指向A的第一个结点 释放头B
typedef struct LNode{//指向结构体成员 必然是结构体指针
  int data;
  struct LNode *next;

}LNode,*LinkList;

int union1(LinkList &A,LinkList B){
    LNode pa;
    pa = A -> next;
    A ->next = B - >next;
    while(B){
       B =B->next;
    }
   B ->next = pa;
  free(B);
   


}