| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 757 人关注过本帖
标题:大神帮我看看这个关于链表的程序
只看楼主 加入收藏
想就进
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-3-19
收藏
 问题点数:0 回复次数:0 
大神帮我看看这个关于链表的程序
#include<stdio.h>
#include<stdlib.h>
struct student
{
    int Xuehao;
    int Score;
    struct student *next;
};
typedef struct student Student;
Student *Create(void)
{
    Student *head=NULL;
    student *p1,*p2;
    int n=0;
    p1=p2=(Student *)malloc(sizeof(Student));
    if(p1!=NULL)
    {
        n++;
        printf("请输入第%d位同学的学号:\n",n);
        scanf("%d",&(p1->Xuehao));
        if(p1->Xuehao!=0)
        {
            printf("请输入第%d位同学的分数:\n",n);
            scanf("%f",&(p1->Score));
            head=p1;
        }
        else
        {
            free(p1);
            return head;
        }
    }
    else
        return head;
    while(1)
    {
        p1=(Student *)malloc(sizeof(Student));
        if(p1!=NULL)
        {
            n++;
            printf("请输入第%d位同学的学号:\n",n);
            scanf("%f",&(p1->Xuehao));
            if(p1->Xuehao!=0)
            {
                printf("请输入第%d位同学的分数:\n",n);
                scanf("%f",&(p1->Score));
                p2->next=p1;
                p2=p1;
            }
            else
            {
                free(p1);
                return p1->next=NULL;
                return head;
            }
        }
    }
}
void Print(Student *head)
{
    Student *p=head;
    printf("\n请输出数据:\n");
    if(head!=NULL)
        do
        {
            printf("%d\t%f\n",p->Xuehao,p->Score);
            p=p->next;
        }while(p!=NULL);
        else
            printf("此链表为空\n");
}
int main()
{
    typedef struct student Student;
    Student *Create(void);
    void Print(Student *);
    Student *head=NULL;
    int k=0;
    while(1)
    {
        printf("1——创建链表\n");
        printf("2——输出链表\n");
        printf("0——退出\n");
        printf("请选择:");
        scanf("%d\n",&k);
        switch(k)
        {
            case 1: head=Create();continue;
            case 2: Print(head);continue;
            case 0: exit(0);
        }
    }
    return 0;
}
搜索更多相关主题的帖子: include Create 
2016-03-20 22:48
快速回复:大神帮我看看这个关于链表的程序
数据加载中...
 
   



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

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