| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 608 人关注过本帖
标题:数据结构代码有bug,求解决
只看楼主 加入收藏
幽醉
Rank: 2
等 级:论坛游民
帖 子:68
专家分:61
注 册:2012-7-30
结帖率:64.29%
收藏
已结贴  问题点数:20 回复次数:1 
数据结构代码有bug,求解决
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#define n 3
int vip1=0;
int y,z;
float sum1=0,sum2=0,sum3=0,sum4=0,sum5=0;
float i1=0,i2=0,i3=0,i4=0,i5=0;
float ave1=0,ave2=0,ave3=0,ave4=0,ave5=0;
struct List
{
  int A[n+1];           //病人来办理业务的N个窗口
  int len;              //表示数组中的元素个数
}L;
struct Lnode
{            //链表结点类型
  int data;
  Lnode *next;
};
struct Linkqueue
{       //链式存储的等候队列的类型定义
  Lnode *front;
  Lnode *rear;
}Q;
void Initshuzu()        //初始化线性的算法
{
  for(int i=1;i<=n;i++)
  L.A[i]=0;             //元素值为0,表示编号为I的窗口当前状态为空
  L.len=0;
}
 void Initqueue()       //初始化队列的算法
{
  Q.front=Q.rear=(Lnode *)malloc(sizeof(Lnode));
  Q.front->next=NULL;
}
void Enqueue(Linkqueue *Q,int elem)  //进队算法,插入elem为q的队尾元素;
{
   Lnode *s;
   s=(Lnode *)malloc(sizeof(Lnode));
   s->data=elem;
   s->next=NULL;
   Q->rear->next=s;
   Q->rear=s;
}
int Dlqueue(Linkqueue *Q)  //出队算法
{
   Lnode *t;
   int x;
   if(Q->front==Q->rear)
   {
       printf("队列为空!\n");
       exit(1);
   }
   else
   {
       t=Q->front->next;
       if(t->next==NULL)
           Q->front=Q->rear=NULL;
       else
           Q->front->next=t->next;
       x=t->data;
       free(t);
       return x;
   }
}
void printl()    //输出数组算法
{
    int i;
    printf("正在办理业务的顾客编号为:  挂号窗口1       挂号窗口2      挂号窗口3\n");
    printf("                             ");
    for( i=1;i<=L.len;i++)
    {
        if(L.A[i]==0)
            continue;
        printf("%d号客户        ",L.A[i]);
      
    }
    printf("\n");
}
void print2()       //输出队列算法
{   
    int i=0;
    printf("正在等候办理业务的顾客编号为:");
    Lnode *s=Q.front->next;
    while(s!=NULL)
    {
        printf("%d ",s->data);
        s=s->next;
        i++;
    }
    printf("\n您的前面一共有%d人在排队,请您稍候!",i);
    printf("\n");

}
void daoda(int x)   //解决病人事件算法
{   
    int i=L.len+1;
    if (L.len<n)   //
        {    L.A[i]=x;
            i++;
            L.len++;
       }
   
    else
    Enqueue(&Q,x);

}
void likai(int x)        //解决病人事件算法
{  
    int i=0;
    do
    {
        if(x>L.len)
        {   
            printf("输入有误!\n请重新输入:");
            scanf("%d",&x);
        }
        else
           for(i=0;i<=L.len;i++)
           {
                if(i==x)
                {
                     printf("尊敬的%d号顾客您好!\n",x);
                     L.A[i]=0;
                     L.len--;
                     if(Q.front!=Q.rear)
                     {
                        int y=Dlqueue(&Q);
                        L.A[i]=y;
                         L.len++;
                     }
                }

           }
    }while(i==0);
}





void time()         //时间函数
{
    time_t timep;
    time (&timep);
     printf("                      现在时刻:%s",ctime(&timep));
}

void main()            //主函数
{
    system("color 3f");                            //屏幕颜色设定
    system("mode con: cols=90 lines=35");
    time_t  a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,end;   
    double  b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,b8=0,b9=0,b10=0,allsum=0,average=0,xi=0;
    double A[10]={0,0,0,0,0,0,0,0,0,0};
    int c,x,v=0,w=0;
    Initshuzu();
    Initqueue();
    double sum=0;
    while(1)
    {  
      printf("\n********************************医院挂号系统******************************************\n");
      printf("\n                                                                                      \n");
      printf("                            1      病人到达\n");
      printf("                            2      病人离开\n");
      printf("                            3      窗口情况查询\n");
      printf("                            4      查看排队情况\n");
      printf("                            5      退出\n\n");
      time();
      printf("\n                          提示:请按回车键进行下一步操作\n");
      printf("\n                                                                                      \n");
      printf("*********************************瑞慈医院*******************************************\n");
      printf("请输入:");
      scanf("%d",&c);
      switch(c)
      {
      case 1:
          {
              system("cls");
              printf("\n*********************************病人到达界面*****************************************\n\n");
              v++;            //计数
                  printf("你的卡号为%d.\n",v);
                  daoda(v);
                  if(v==1)
                  {
                      a1=time(NULL);     //v=1的客户到达时间
                      system("pause");
                  }   
                  else if(v==2)
                  {
                      a2=time(NULL);
                      system("pause");
                  }
                  else if(v==3)
                  {
                      a3=time(NULL);
                      system("pause");
                  }
                  else if(v==4)
                  {
                      a4=time(NULL);
                      system("pause");
                  }
                  else if(v==5)
                  {
                      a5=time(NULL);
                      system("pause");
                  }
                  else if(v==6)
                  {
                      a6=time(NULL);
                      system("pause");
                  }
                  else if(v==7)
                  {
                      a7=time(NULL);
                      system("pause");
                  }
                  else if(v==8)
                  {
                      a8=time(NULL);
                      system("pause");
                  }
           
                  else if(v==9)
                  {
                      a9=time(NULL);
                      system("pause");
                  }
                  else if(v==10)
                  {
                      a10=time(NULL);
                      system("pause");
                  }
                  else
                  {
                      printf("请稍候拿号,谢谢!");
                      system("pause");
                  }
              
              system("cls");
              break;
          }
      case 2:
          {
              system("cls");
              printf("\n************************************病人离开界面******************************************\n\n");
              printf("请输入离开病人的编号:\n");
              scanf("%d",&x);
              likai(x);
              
              w++;
              if(x=1)
              {
                  
                  printf("挂号结束,祝您早日康复!");
              }
              else if(x=2)
              {
                  
                   printf("挂号结束,祝您早日康复!");
              }
              else if(x=3)
              {
                   printf("挂号结束,祝您早日康复!");
              }
              else if(x=4)
              {
                   printf("挂号结束,祝您早日康复!");
              }
              else if(x=5)
              {
                  printf("挂号结束,祝您早日康复!");
              }
              else if(x=6)
              {
                  printf("挂号结束,祝您早日康复!");
              }
             else if(x=7)
             {
                   printf("挂号结束,祝您早日康复!");
             }
             else if(x=8)
             {
                   printf("挂号结束,祝您早日康复!");
             }
             else if(x=9)
             {
                  printf("挂号结束,祝您早日康复!");
             }
             else if(x=10)
             {
                  printf("挂号结束,祝您早日康复!");
             }
            
             getch();
             system("cls");
             break;
          }


     case 3:
          {   
              system("cls");
              printf("\n***********************************窗口查询界面*******************************************\n\n");
              printl();
              getch();
              system("cls");
              break;
      
          }

      
         
      case 4:
          {
              system("cls");
              printf("\n**********************************排队查询界面*******************************************\n\n");
              print2();
              getch();
              system("cls");
              break;
          }

      case 5:
          return;
          getch();
          system("cls");
      default: printf("输入有误!请重新输入:\n");
          getch();
          system("cls");
    }
  }
}
在这段代码中,当有四个病人进入,之后出去一个病人,再调用排队查询时会报错,为什么,求大神解决!!!
搜索更多相关主题的帖子: include 元素 
2013-06-24 11:48
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:20 
调试一下,会调试把

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-06-25 12:04
快速回复:数据结构代码有bug,求解决
数据加载中...
 
   



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

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