Chinaunix首页 | 论坛 | 博客
  • 博客访问: 70337
  • 博文数量: 21
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 245
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-28 14:14
文章分类

全部博文(21)

文章存档

2011年(1)

2010年(14)

2009年(6)

我的朋友

分类: C/C++

2009-10-13 17:02:36

#include
#include
typedef struct Node
{
  int data;
  Node *next;
} node,*linklist;
/*
该函数用来创建链表
*/
linklist creat(linklist head)
{
     node *r,*s;
     int a;
     r = (linklist)malloc(sizeof(node));
     head = r;
     scanf("%d",&a);
     while(a != 0)
     {
        s =(node*)malloc(sizeof(node));
        s->data=a;
        r->next=s;
        r=s;
        printf("please input a data:");
        scanf("%d",&a);
     }
     r->next=NULL;
     return head;
}
/*用于实现链表A,B的组合*/
linklist mergel(linklist A,linklist B)
{
     node *p,*q,*s,*t;
     linklist C;
     p=A->next;
     q=B->next;
     C=A;
     while(p&&q)
     {
       s=p->next;
       p->next=q;
       if(s)
       {
            t=q->next;
            q->next=s;
       }
       p=s;
       q=t;
     }
     return C;
}

int main()
{
    linklist p,A,B,C;
    printf("Creat linklist A:");
    A = creat(A);
    printf("Creat linklist B:");
    B = creat(B);
    C = mergel(A,B);
    p = C->next;
    while(p)
    {
            printf("%d\n",p->data);
            p = p->next;        
    }
    printf("Over\n");
    getchar();
    getchar();
    return 0;
        
}
 
阅读(653) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~