| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 379 人关注过本帖
标题:两个简单链表的简单链接
只看楼主 加入收藏
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
结帖率:100%
收藏
 问题点数:0 回复次数:6 
两个简单链表的简单链接
程序代码:
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct student)

struct student
{
    float num;
    int score;
    struct student *next;
};

struct student *creat_o(void)
{
    struct student *p,*p1,*head;
    int n=0;
    head=(struct student *)malloc(LEN);
    p=head;
    printf("please input the first node date\n");
    scanf("%f%d",&p->num,&p->score);

    while(p->next!=NULL)
    {
        if(p->num!=0)
        {
            p1=p;
            printf("please input the %d date\n",++n);
            p=(struct student *)malloc(LEN);
            scanf("%f%d",&p->num,&p->score);
            p1->next=p;
        }
        else
            p->next=NULL;
    }
    p1->next=NULL;
    return(head);//if no ()
}

struct student *creat_t(void)
{
    struct student *p,*p1,*head;
    int n=0;
    head=(struct student *)malloc(LEN);
    p=head;
    printf("please input the first node date\n");
    scanf("%f%d",&p->num,&p->score);

    while(p->next!=NULL)
    {
        if(p->num!=0)
        {
            p1=p;
            printf("please input the %d date\n",++n);
            p=(struct student *)malloc(LEN);
            scanf("%f%d",&p->num,&p->score);
            p1->next=p;
        }
        else
            p->next=NULL;
    }
    p1->next=NULL;
  return(head);//if no ()
}

int main()
{
    struct student *head,*p[3];

    p[0]=creat_o();                    // can't have 'void' in ()
    p[1]=creat_t();


    if(p[0]->num>p[1]->num)
    {
          head=p[1];
        while(p[1]->next!=NULL)
                p[1]=p[1]->next;
        p[1]->next=p[0];
    }
    else
    {
            head=p[0];
          while(p[0]->next!=NULL)
                p[0]=p[0]->next;
           p[0]->next=p[1];
    }

    p[2]=head;
    printf("follows are the linked\n");
    while(p[2]!=NULL)
    {
        printf("%0.0f%4d\n",p[2]->num,p[2]->score);
        p[2]=p[2]->next;
    }
    return 0;
}
第一次写的   欢迎大家提出改进意见  谢了
2011-05-25 18:12
ansic
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:恍惚窈冥
等 级:城市猎人
帖 子:1543
专家分:5367
注 册:2011-2-15
收藏
得分:0 
学习一下先!

善人者,不善人之师;不善人者,善人之资。不贵其师,不爱其资,虽智大迷。
2011-05-25 19:38
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
收藏
得分:0 
你谦虚了啊 呵呵
2011-05-25 22:00
fz19910125
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:52
专家分:11
注 册:2010-10-12
收藏
得分:0 
学习学习 。。。
2011-05-26 09:27
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:0 
实现与接口分开。。。。

我们都在路上。。。。。
2011-05-26 10:35
jacksongod
Rank: 2
等 级:论坛游民
帖 子:32
专家分:82
注 册:2011-5-18
收藏
得分:0 
不止两个的话写法就有点不一样了。。
2011-05-26 12:14
mahuangchao
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2011-1-3
收藏
得分:0 
2011-05-27 15:33
快速回复:两个简单链表的简单链接
数据加载中...
 
   



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

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