| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 436 人关注过本帖
标题:链表排序问题
取消只看楼主 加入收藏
G梦
Rank: 1
等 级:新手上路
帖 子:48
专家分:7
注 册:2012-12-27
结帖率:88.89%
收藏
已结贴  问题点数:20 回复次数:2 
链表排序问题
求指导,如何给链表排序,顺便帮我看看这段代码错哪儿了,VC总是提示有空串
谢谢啦

#include<stdio.h>
#include<stdlib.h>
#define len sizeof(struct student)
struct student
{
    char name[30];
    int score1;
    int score2;
    int score3;
    int all;
    struct student *next;
};
int n;
struct student*creat()
{
    struct student*head;
    struct student*p1,*p2; n=0;
    p1=p2=(struct student*)malloc(len);
    scanf("%s%d%d%d",&p1->name,&p1->score1,&p1->score2,&p1->score3);
    head=NULL;
     
    while(p1->name!='')
    {  
        n=n+1;  
        if(n==1)head=p1;  
        else p2->next=p1;  
        p2=p1;  
        p1=(struct student*)malloc(len);  
        scanf("%s%d%d%d",&p1->name,&p1->score1,&p1->score2,&p1->score3);
    }
    p2->next=NULL;
    return(head);
}
int main()
{
    struct student*pt;
    pt=creat();
    printf("总评1:%d",pt->all=(pt->score1+pt->score2+pt->score3));
    printf("总评2:%d",pt->next->all=(pt->next->score1+pt->next->score2+pt->next->score3));
    printf("总评3:%d",pt->next->next->all=(pt->next->next->score1+pt->next->next->score2+pt->next->next->score3));
 }

搜索更多相关主题的帖子: next all include 如何 
2013-01-21 14:09
G梦
Rank: 1
等 级:新手上路
帖 子:48
专家分:7
注 册:2012-12-27
收藏
得分:0 
怎么不是了?
2013-01-22 19:20
G梦
Rank: 1
等 级:新手上路
帖 子:48
专家分:7
注 册:2012-12-27
收藏
得分:0 
回复 4楼 神龙赖了
弱弱的问一句 strucdt student *p1,*p2;n=0;这段代码有什么问题吗?
2013-01-26 23:35
快速回复:链表排序问题
数据加载中...
 
   



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

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