- 论坛徽章:
- 0
|
为什么这个程序,运行后,显示的是无限循环
#include<iostream.h>
#define MAXLENGTH 1024
typedef struct
{
int data[MAXLENGTH];
int rear,front;
int num;
}c_SeQueue;
int Init_SeQueue(c_SeQueue **q)
{
if((*q)=new(c_SeQueue)) return 0;
(*q)->front=MAXLENGTH;
(*q)->rear=MAXLENGTH;
(*q)->num=0;
return 1;
}
int In_SeQueue(c_SeQueue *q,int x)
{
if(q->num==MAXLENGTH)
{
cout<<"队满";
return -1;
}
else
{
q->rear=(q->rear+1)%MAXLENGTH;
q->data[q->rear]=x;
q->num++;
return 1;
}
}
int out_SeQueue(c_SeQueue *q,int *x)
{
if(q->num==0)
{
cout<<"队空";
return -1;
}
else
{
q->front=(q->front+1)%MAXLENGTH;
*x=q->data[q->front];
q->num--;
return 1;
}
}
int Empty_SeQueue(c_SeQueue *q)
{
if(q->num==0) return 1;
else return 0;
}
void conversion(double n,int r)
{
// double n;
int X,N,M;
double y,m;
N=n;
y=n-N;
c_SeQueue *q;
Init_SeQueue(&q);
while(y!=0)
{
m=y*r;
M=m;
y=m-M;
int i=0;
if(i<9)
{
In_SeQueue(q,M);
i++;
}
else
break;
}
while(!Empty_SeQueue(q))
{
out_SeQueue(q, &X);
if(M>=10)
{ switch(X)
{
case 10: cout<<'A'; break;
case 11: cout<<'B'; break;
case 12: cout<<'C'; break;
case 13: cout<<'D'; break;
case 14: cout<<'E'; break;
case 15: cout<<'F'; break;
}
}
else
cout<<X;
}
cout<<endl;
}
void main()
{
double n;
int r;
cout<<"请输入您要转化的数及想要转化为几进制:"<<endl;
cin>>n>>r;
cout<<"转化结果为:"<<endl;
conversion(n,r);
}
[ 本帖最后由 crazy4444 于 2008-11-30 12:08 编辑 ] |
|