| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 526 人关注过本帖
标题:链表的问题,这个怎么改呢?
只看楼主 加入收藏
拐角的认识
Rank: 2
等 级:论坛游民
帖 子:12
专家分:12
注 册:2010-4-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
链表的问题,这个怎么改呢?

 
#include<malloc.h>
#include <stdio.h>
#include<string.h>
#define len sizeof(struct student)
#define NULL 0
struct student{
  char num[20];
 char name[20];
 float score[3];
 float zongfen;
 struct student *next;
};
int count=0;
struct student * input();
struct student * inset(struct student *head,struct student *stu);
struct student * deleted(struct student *head,char *name);
void search(struct student *head,char *name);
struct student * paixu(struct student *head,int count);
struct student * jisuan(struct student *head);
int main(void)
{
struct student *head,*p;
char num[20];
 char name[20];
 int choice,i;
 do{
  printf("1:input() 2:inset() 3:deleted() 4:search() 5:paixu() 6:jisuan()");
        
  printf("enter chioce:");
  scanf("%d",&choice);
  switch(choice){
  case 1:
   head=input();
   break;
  case 2:
   printf("input num and name:");
   scanf("%d%s",num,name);
   p= (struct student * ) malloc(len);
   strcpy(p->num,num);
   strcpy(p->name,name);
   printf("enter shuxu english cyuyan:");
   for(i=0;i<3;i++)
    scanf("%s",p->score[i]);
   head=inset(head,p);
   break;
  case 3:
   printf("input name:");
   scanf("%s",name);
   head=deleted(head,name);
    break;
  case 4:
   printf("input name:");
   scanf("%s",name);
   search(head,name);
   break;
  case 5:
   head=paixu(head,count);
   break;
  case 6:
   head=jisuan(head);
   break;
  case 0:
   break;
 }
 }while(choice!=0);
 return 0;
}
 struct student * input()
{struct student *head,*p1,*p2;
 int i;
p1=p2=(struct student * ) malloc(len);
printf("enter num and name:");
scanf("%s%s",p1->num,p1->name);
printf("enter shuxu english cyuyan:");
   for(i=0;i<3;i++)
    scanf("%s",p1->score[i]);
   head=NULL;
   while(p1->num!=0){
    count=count+1;
    if(count==1)
     head=p1;
    else
     p2->next=p1;
    p2=p1;
p1=p2=(struct student * ) malloc(len);
printf("enter num and name:");
scanf("%s%s",p1->num,p1->name);
printf("enter shuxu english cyuyan:");
   for(i=0;i<3;i++)
    scanf("%s",p1->score[i]);}
   p2->next=NULL;
   return head;
 }
 struct student * insert(struct student *head,struct student *stud)
 {
  struct student *p0,*p1,*p2;
  p1=head;
  p0=stud;
  if(head==NULL){
   head=p0;
   p0->next=NULL;}
  else
  {
   while((p0->num>p1->num)&&(p1->next!=NULL))
   {
    p2=p1;
    p1=p1->next ;}
   if(p0->num <=p1->num )
   {
    if(head==p1)
     head=p0;
    else
     p2->next=p0;
    p0->next=p1;}
   else
   {
    p1->next =p0;
    p0->next =NULL;}
   count=count+1;
   return (head);
 }return 0;}
struct student * deleted(struct student *head,char *name)
{
 struct student *p1,*p2;
 if(head==NULL)
 {
  printf("not list");
  return head;
 }
 p1=head;
 while((name!=p1->name)&&(p1->next!=NULL))
 {
  p2=p1;
  p1=p1->next ;}
 if(name==p1->name )
 {
  if(head==p1)
   head=p1->next;
  else
   p2->next=p1->next;
  printf("deletr:%s\n",name);}
 else
  printf("%s not been found\n",name);
 count=count-1;
 return head;}
 
void search(struct student *head,char *name)
{
 struct student *p1;char *p3;
 p3=name;
 int flag,i;
 p1=head;
    flag=1;
 for(p1=head;p1;p1->next )
  if(p1->name==p3)
  {
   flag=1;
   break;
  }
  else
   printf("not found");
  if(flag)
  {
   printf("%s%20s\n",p1->num,p1->name);
   for(i=0;i<3;i++)
    printf("%f\n",p1->score[i]);
}}
struct student * paixu(struct student *head,int count)
{
 void shuxuepx(struct student *head,int count);
 void englishpx(struct student *head,int count);
 void cyuyanpx(struct student *head,int count);
 void zongfenpx(struct student *head,int count);
 int choice;
 do{
 printf("1:shuxuepx 2:englishpx 3:cyuyanpx 4:zongfenpx 0:退出");
  scanf("%d",&choice);
 switch(choice){
 case 1:
   shuxuepx(head,count);
   break;
 case 2:
   englishpx(head,count);
   break;
 case 3:
   cyuyanpx(head,count);
   break;
 case 4:
   zongfenpx(head,count);
   break;}
 }while(choice!=0);
return 0;
}
void shuxuepx(struct student *head,int count)
{
 struct student *p1,*p2;
 int i,j;
float temp;
 for(p1=head,i=1;i<count;p1=p1->next ,count++){
  p2=p1;
  for(p1=p1->next,j=i+1;j<=count;p1->next,j++)
  if(p1->score[0]<p2->score[0])
   p2->score[0]=p1->score[0];
  temp=p2->score[0];
  p2->score[0]=head->score[0];
  head->score[0]=temp;
  head=head->next;}
 }
void englishpx(struct student *head,int count)
{
 struct student *p1,*p2;
       int i,j;
       float temp;
  for(p1=head,i=1;i<count;p1=p1->next ,count++){
    p2=p1;
    for(p1=p1->next,j=i+1;j<=count;p1->next,j++)
       if(p1->score[1]<p2->score[1])
        p2->score[1]=p1->score[1];
         temp=p2->score[1];
          p2->score[1]=head->score[1];
          head->score[1]=temp;
           head=head->next;
  }
         
}
void cyuyanpx(struct student *head,int count)
{
 struct student *p1,*p2;
 int i,j;
 float temp;
  for(p1=head,i=1;i<count;p1=p1->next ,count++){
    p2=p1;
    for(p1=p1->next,j=i+1;j<=count;p1->next,j++)
       if(p1->score[2]<p2->score[2])
        p2->score[2]=p1->score[2];
         temp=p2->score[2];
          p2->score[2]=head->score[2];
          head->score[2]=temp;
           head=head->next;
  }
     
}

struct student * jisuan(struct student *head)
{
 void gerenzongfen(struct student *head);
 void syrdkpjf(struct student *head);
 int choice;
 do{
 printf("1:计算个人总分平均分 2:所有人的单科平均分0:退出:");
  scanf("%d",&choice);
 switch(choice){
  case 1:
   gerenzongfen(head);
   break;
  case 2:
   syrdkpjf(head);
   break;}
 }while(choice!=0);
 return 0;
}
void gerenzongfen(struct student *head)
 {
 struct student *p1;
 int i;
 float sum,averge;
 p1=head;
 for(p1=head;p1;p1=p1->next )
 {
  sum=0;
  for(i=0;i<3;i++)
   sum=sum+p1->score[0];
  averge=sum/3;
  printf("%s%f%f",p1->name,sum,averge);
 }}
 void syrdkpjf(struct student *head)
 {
         void shuxue(struct student *head);
         void english(struct student *head);
      void cyuyan(struct student *head);
 
  int choice;
  do{
   printf("1:shuxue 2:english: 3:c yuyan 0:退出");
   scanf("%d",&choice);
   switch(choice){
   case 1:
       shuxue(head);
    break;
   case 2:
    english(head);
    break;
   case 3:
    cyuyan(head);
    break;}
   }while(choice!=0);
 }
 void shuxue(struct student *head)
 {
  struct student *p1;
  int n=0;
  float sum=0;
 
  for(p1=head;p1;p1->next )
  {
   sum=sum+p1->score[0];
   n++;}
  printf("shuxue averge%f",sum/n);
 }
void english(struct student *head)
 {
  struct student *p1;
  int n=0;
  float sum=0;
  
  for(p1=head;p1;p1->next )
  {
   sum=sum+p1->score[0];
   n++;}
  printf("english averge%f",sum/n);
 }
void cyuyan(struct student *head)
{
  struct student *p1;
  int n=0;
  float sum=0;
  
  for(p1=head;p1;p1->next )
  {
   sum=sum+p1->score[0];
   n++;}
  printf("c yuyan averge%f",sum/n);
 }
搜索更多相关主题的帖子: 链表 
2010-06-20 20:23
我菜119
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:938
专家分:1756
注 册:2009-10-17
收藏
得分:10 
你可倒好,整个大程序来叫人给改??挺有想法呀??

愿用余生致力编程
2010-06-20 22:34
waterstar
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:984
专家分:2810
注 册:2010-2-12
收藏
得分:10 
我说,编程风格不好,这种没注释,编程风格不好的程序最烦了

冰冻三尺,非一日之寒;士别三日,不足刮目相看!
2010-06-20 22:47
拐角的认识
Rank: 2
等 级:论坛游民
帖 子:12
专家分:12
注 册:2010-4-5
收藏
得分:0 
不好意思,这是我自己编的。
下次会注意编程风格的。
这个程序的问题已经解决了。
2010-07-05 23:10
快速回复:链表的问题,这个怎么改呢?
数据加载中...
 
   



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

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