| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 442 人关注过本帖
标题:求改错,程序不报错,但是不能运行,好像成死循环了
只看楼主 加入收藏
ai1360115461
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-6-27
结帖率:0
收藏
 问题点数:0 回复次数:1 
求改错,程序不报错,但是不能运行,好像成死循环了
#define NULL 0
#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct goods{
             int num1;
             char name[10];
             char sex[6];
             int grades[5];                                             
             struct goods *next;
};
struct goods *creat(int n)
{
    struct goods *pb,*pf,*head;
    int i,k;
    printf("please input the information(学号,名字,性别,成绩)\n");
    for(i=0;i<n;i++)
       {
           pb=(struct goods*)malloc(sizeof(struct goods));
           scanf("%d%s%s",&pb->num1,pb->name,pb->sex);
           for(k=0;k<5;k++)
              scanf("%d",&pb->grades[k]);
        if(i==0)
          {
              head=pb;
              pf=pb;
          }
        else
          {
              pf->next=pb;
          }
        pb->next=NULL;
        pf=pb;
       }
       return head;
}
int total(struct goods *head)
{
    struct goods *pb;
    int i;
    for(i=0,pb=head;pb!=NULL;pb=pb->next,i++)
    ;
    return i;
}
struct goods *ordination3(struct goods *head,int n)
{
    void out(struct goods *head);
    struct goods *pb,*pf,*pf2,*pff,*p,*pc,*pz;
    int min,i,k;
    for(i=0;i<n-1;i++)
       {
           pc=head;
           for(k=0;k<i;k++)
               pc=pc->next;
           pff=head;
           for(k=0;k<i-1;k++)
               pff=pff->next;
        pb=(struct goods*)malloc(sizeof(struct goods));
        pb=pc;
        min=pc->num1;
        p=pc;
        for(pf=pb;pb!=NULL;pb=pb->next)
           {
               if(min<pb->num1)
                 {
                     pf2=pf;
                     p=pb;
                     min=pb->num1;
                 }
               pf=pb;
           }
        if(pc!=p)
         {
        if(pc==head)
          {
              pz=(struct goods*)malloc(sizeof(struct goods));
              if(pc->next!=p)
                {
                    pf2->next=pc;
                    pz->next=p->next;
                    p->next=pc->next;
                    pc->next=pz->next;
                    head=p;
                }
              else
                {
                pc->next=p->next;
                p->next=pc;
                    head=p;
                }
          }
        else if(pc!=head)
          {
              pz=(struct goods*)malloc(sizeof(struct goods));
              if(pc->next==p)
                {
                    pff->next=p;
                pc->next=p->next;
                p->next=pc;
                }
              else if(pc->next!=p)
                {
                    pff->next=p;
                    pf2->next=pc;
                    pz->next=p->next;
                    p->next=pc->next;
                    pc->next=pz->next;
                }
          }
         }
       }
       return head;      
}
void find(struct goods *head,int num)
{
    struct goods *pb,*p;
    int k;
    p=head;
    for(pb=head;pb!=NULL;pb=pb->next)
       {
           if(num==pb->num1)
             {
                 p=pb;
             }
       }
    if(num==p->num1)
    printf("学号=%d名字=%s性别=%s\n",p->num1,p->name,p->sex);
    printf("成绩\n");
    for(k=0;k<5;k++)
       printf("%d ",p->grades[k]);
}        
void modify(struct goods *head,int num1)
{
    struct goods *pb;
    int k;
    for(pb=head;pb!=NULL;pb=pb->next)
    {
        if(num1==pb->num1)
           break;
    }
    printf("please input your all message in this thing:sequence numbers,name,price,the numbers,brand\n");
    scanf("%d%s%s",&pb->num1,pb->name,pb->sex);
           for(k=0;k<5;k++)
              scanf("%d",&pb->grades[k]);
    printf("学号=%d名字=%s性别=%s\n",pb->num1,pb->name,pb->sex);
    printf("成绩\n");
    for(k=0;k<5;k++)
       printf("%d ",pb->grades[k]);
}   
struct goods *delect(struct goods *head,int num1)
{
  struct goods *pf,*pb,*p,*pf2;
  p=head;
  pf2=head;
  for(pb=head;pb!=NULL;pb=pb->next)
     {
         if(num1==pb->num1)
           {
               p=pb;
               pf2=pf;
           }
           pf=pb;
     }
     if(p==head)
           head=head->next;
     else
        pf2->next=p->next;
     return head;
}                  
struct goods *insert(struct goods *head,struct goods *pi)
{
    struct goods *end,*pb,*pf;
    for(end=head;end->next!=NULL;end=end->next)
        ;
    if(pi->num1<=head->num1)
      {
          pi->next=head;
          head=pi;
      }
    else if(pi->num1>head->num1&&pi->num1<=end->num1)
      {
          for(pb=head;pb->num1<=pi->num1&&pb!=NULL;)
             {
                 pf=pb;
                 pb=pb->next;
             }
          pf->next=pi;
          pi->next=pb;
      }
    else
      {
          end->next=pi;
          pi->next=NULL;
      }
    return head;
}
void out(struct goods *head)
{
    struct goods *pb;
    int k;
    pb=head;
    for(;pb!=NULL;pb=pb->next)
    {
        printf("学号=%d名字=%s性别=%s\n",pb->num1,pb->name,pb->sex);
    printf("成绩\n");
    for(k=0;k<5;k++)
       printf("%d ",pb->grades[k]);
    printf("\n");
    }
    printf("\n");
}
void main()
{
    struct goods *head,*pi;
    int i,k;
    for(;1;)
    {
    printf("1、存储10个以上学生的基本数据\n");
    printf("2、直接输出检验\n");
    printf("3、查找指定学生的信息\n");
    printf("4、修改指定学生的信息\n");
    printf("5.删除指定学生的信息\n");
    printf("6、在指定的学生前或后再插入一个物品的信息\n");
    printf("输入想要执行的程序\n");
    scanf("%d",&i);
    switch(i){
    case 1:
    printf("1、存储10个以上学生的基本数据(包括物品学号,名字,性别,成绩)\n");
    printf("请输入你要存储的数据量\n");
    scanf("%d",&i);
    head=creat(i);break;
    case 2:out(head);printf("\n");break;
    case 3:
    printf("3、查找指定学生的信息\n");
    printf("请输入要查找的物品编号\n");
    scanf("%d",&k);
    find(head,k);break;
    case 4:
    printf("4、修改指定学生的信息\n");
    printf("请输入你想要改变的编号\n");
    scanf("%d",&k);
    modify(head,k);
    out(head);break;
    case 5:
    printf("5.删除指定学生的信息\n");
    printf("请输入你要删除的编号\n");
    scanf("%d",&k);
    head=delect(head,k);
    out(head);break;
    case 6:
    printf("6、在指定的学生前或后再插入一个物品的信息\n");
    printf("将按编号自动插入\n");
    head=ordination3(head,total(head));
    printf("please input your message(包括物品学号,名字,性别,成绩)\n");
    pi=(struct goods *)malloc(sizeof(struct goods));
    scanf("%d%s%s",&pi->num1,pi->name,pi->sex);
           for(k=0;k<5;k++)
              scanf("%d",&pi->grades[k]);
    head=insert(head,pi);
    out(head);break;
    default:printf("error\n");
    }
    }
}
搜索更多相关主题的帖子: head next include please 
2012-06-27 18:00
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
设置断点查找死循环位置

授人以渔,不授人以鱼。
2012-06-28 12:39
快速回复:求改错,程序不报错,但是不能运行,好像成死循环了
数据加载中...
 
   



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

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