| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 354 人关注过本帖
标题:以解决了。。不过还是留着吧,给和我一样的新手参考一下,稍微改了一下
只看楼主 加入收藏
xdh0817
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:193
专家分:195
注 册:2011-10-20
结帖率:92.86%
收藏
已结贴  问题点数:20 回复次数:3 
以解决了。。不过还是留着吧,给和我一样的新手参考一下,稍微改了一下
#include<stdio.h>
#include<malloc.h>
#define len sizeof(struct student)
struct student
 { long num;
     float score;
     struct student *next;
 };
struct student *creat(void)
 { struct student *p1,*p2,*head;
     int n=0;
     p1=p2=(struct student *)malloc(len);
     printf("请输入学号和成绩(格式为:学号,成绩。输入0则结束):\n");
     scanf("%ld,%f",&p1->num,&p1->score);
     head=NULL;
     while(p1->num!=0)
     {   n++;
         if(n==1)  head=p1;
         else p2->next=p1;
         p2=p1;
         p1=(struct student *)malloc(len);
         scanf("%ld,%f",&p1->num,&p1->score);
     }
     p2->next=NULL;
     return(head);
 }
 void output(struct student *head)
 {
     struct student *p;
     p=head;
     if(head!=NULL)
     printf("输出成绩:\n");
     do
     { printf("%ld   %.0f\n",p->num,p->score);
         p=p->next;
     }while(p!=NULL);
 }
 struct student *shan(struct student *head,long x)
 {
  struct student *p1,*p2;
      p1=head;
      while(x!=p1->num&&p1->next!=NULL)
      { p2=p1;p1=p1->next;}
       p2->next=p1->next;
          printf("%ld\n",x);
      
      return(head);
}
 void main()
 {   long x;
     struct student *p,*head;
     head=creat();
     p=head;
     output(p);
     printf("请输入要删除学生的学号:");
     scanf("%ld",&x);
     p=(struct student *)shan(p,x);
     output(p);
}

[ 本帖最后由 xdh0817 于 2011-11-13 00:27 编辑 ]
搜索更多相关主题的帖子: include 
2011-11-12 23:47
heroinearth
Rank: 10Rank: 10Rank: 10
来 自:云南曲靖
等 级:青峰侠
帖 子:430
专家分:1506
注 册:2011-10-24
收藏
得分:10 
程序代码:
#include<stdio.h>
#include<malloc.h>
#define len sizeof(struct student)
struct student
{ long num;
     float score;
     struct student *next;
};
struct student *creat(void)
{ struct student *p1,*p2,*head;
     int n=0;
     p1=p2=(struct student *)malloc(len);
     scanf("%ld,%f",&p1->num,&p1->score);
     head=NULL;
     while(p1->num!=0)
     {   n++;
         if(n==1)  head=p1;
         else p2->next=p1;
         p2=p1;
         p1=(struct student *)malloc(len);
         scanf("%ld,%f",&p1->num,&p1->score);
     }
     p2->next=NULL;
     return(head);
}
void output(struct student *head)
{
     struct student *p;
     p=head;
     if(head!=NULL)
     do
     { printf("%ld   %.0f\n",p->num,p->score);
         p=p->next;
     }while(p!=NULL);
}
struct student *del(struct student *head,long num)
{
  struct student *p1,*p2;
      if(head==NULL) {printf("cuowu"); goto end;}//在这里
      p1=head;
      while(num!=p1->num&&p1->next!=NULL)
      { p2=p1;p1=p1->next;}
      if(num==p1->num)
      {if(p1==head) head=p1->next;
          else p2->next=p1->next;
          printf("%ld\n",num);
      }
      else printf("%ld is not found\n",num);
      return(head);
}
void main()
{   long num;
     struct student *p,*head;
     head=creat();
     p=head;
     output(p);
     scanf("%ld",&num);
     p=(struct student *)del(p,num);
     output(p);
}
2011-11-13 00:03
xdh0817
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:193
专家分:195
注 册:2011-10-20
收藏
得分:0 
回复 2楼 heroinearth
已经改好了,不过还是谢谢喽
2011-11-13 00:05
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:10 
回复 楼主 xdh0817
if(head==NULL) {printf("cuowu"); goto end;}

总有那身价贱的人给作业贴回复完整的代码
2011-11-13 00:06
快速回复:以解决了。。不过还是留着吧,给和我一样的新手参考一下,稍微改了一下 ...
数据加载中...
 
   



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

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