| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 940 人关注过本帖
标题:大家帮我看看这个程序!
取消只看楼主 加入收藏
whbc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:180
专家分:139
注 册:2010-3-31
结帖率:89.66%
收藏
已结贴  问题点数:20 回复次数:1 
大家帮我看看这个程序!
大家帮我看看这个程序!输入时候一直输下去了,没有反应(创建链表的时候)!
程序代码:
#include <stdio.h>
#include <stdlib.h>


 struct student

 { 
     char name[8];
     float high;
     long int weight;
     struct student *next;

 };


 int n,i;

 struct student *creat()//创建链表
 { 
      i=1;
     struct student *p,*head,*stud;
     head=NULL;
     stud=p=(struct student *)malloc(sizeof(struct student));
     printf("请输入学生 %d 的身高体重姓名:",i);
     scanf("%s%f%ld",&stud->high,&stud->weight,&stud->name);
    
     while(stud->high!=0)
     {
         n++;
         if(n==1)
         {  
             head=stud;
             head->next=NULL;
         }
         else
             p->next=stud;
             p=stud;
          stud=(struct student *)malloc(sizeof(struct student));
          printf("请输入学生 %d 的姓名身高体重:",++i);
          scanf("%s%f%ld",&stud->high,&stud->weight,&stud->name);
         
     }
     p->next=NULL;
     return(head);

 }



 struct student * search(struct student *head)//找出高度最高的那个学生
 {  
     struct student *p,*q,*t;
     float k;
     t=p=head;
     do
     { 
         if(t->high<p->high)
         {
              k=t->high;
              t->high=p->high;
              p->high=k;
              q=p;
         }
         p=p->next;
     }while(p!=NULL);
         return q;


 }


 struct student * find(struct student *head)//找出体重最重的那个学生
 { 
     struct student *p,*q,*t;
     int m;
     t=p=head;
     do
     {
         if(t->weight<p->weight)
         {
             m=t->weight;
             t->weight=p->weight;
             p->weight=m;
             q=p;
         }
         p=p->next;
     }while(p!=NULL);
    
    return q;

 }



 void  main(void)

 { 
     struct student *p,*q,*head;
     head=creat();
     p=search(head);
     printf("%s%f%ld",p->high,p->weight,p->name);
     q=find(head);
     printf("%s%f%ld",p->high,p->weight,p->name);
     
     

 }

搜索更多相关主题的帖子: next color 
2010-12-14 09:51
whbc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:180
专家分:139
注 册:2010-3-31
收藏
得分:0 
回复 7楼 xiaomarn
嗯,请大侠指点了!!谢谢!!

付出终将有回报!Ibelieve!
2010-12-14 23:19
快速回复:大家帮我看看这个程序!
数据加载中...
 
   



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

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