| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 520 人关注过本帖
标题:输入两个单向链表并输出第二个链表
取消只看楼主 加入收藏
wxh525123
Rank: 2
等 级:论坛游民
帖 子:38
专家分:37
注 册:2010-4-18
结帖率:100%
收藏
已结贴  问题点数:30 回复次数:1 
输入两个单向链表并输出第二个链表
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
struct student
{
    int num;
    float score;
    struct student *next;
    };
int n=0;
void main()
{
    struct student *creat(void);
    void print();
    struct student *heada,*headb;
    printf("input list a;\n");
    heada=creat();
    printf("input list b:\n");
    headb=creat();
    print(headb);
    getch();
    }
struct student *creat()
{
    struct student *head,*p1,*p2;
    printf("input number&score of student:\n");
    p1=p2=(struct student *)malloc(LEN);
    scanf("%ld%f",&p1->num,&p2->score);
    head=NULL;
    while(p1->num!=0)
        {
            n++;
            if(n==1)
                head=p1;
            else
                p2->next=p1;
            p2=p1;
            p1=(struct student *)malloc(LEN);
            scanf("%ld%f",&p1->num,&p1->score);
            }
    p2->next=NULL;
    return head;
    }
void print(struct student *head)
{
    struct student *p;
    p=head;
    if(head==NULL)
        printf("the empty list!\n");
    else
        while(p!=NULL)
            {
                printf("%d %4.2f\n",p->num,p->score);
                p=p->next;
                }
    }
求高人指点一下,为什么第二次调用creat()函数执行错误?是不是只能建立一个链表呢?
谢谢了
搜索更多相关主题的帖子: 链表 输出 输入 
2010-05-13 10:33
wxh525123
Rank: 2
等 级:论坛游民
帖 子:38
专家分:37
注 册:2010-4-18
收藏
得分:0 
回复 2楼 yc2575757
非常感谢
2010-05-13 13:16
快速回复:输入两个单向链表并输出第二个链表
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011298 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved