#include"stdio.h"
#include"stdlib.h"
#define MAXQSIZE 100
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int QElemType;
typedef int Status;
typedef struct
{
QElemType *base;//初始化的动态分配存储空间
int front;//头指针
int rear;//尾指针
}SqQueue;
Status InitQueue(SqQueue &Q){
Q.base=(QElemType *)malloc(sizeof(QElemType)*MAXQSIZE);
if(!Q.base) return OVERFLOW;
Q.front=0;
Q.rear=0;
return OK;
}
Status InQueue(SqQueue &Q,QElemType e){
if(Q.rear==MAXQSIZE) return ERROR;//判满
Q.base[Q.rear]=e;
Q.rear++;
return OK;
}
Status OutQueue(SqQueue &Q,QElemType &e){
if(Q.rear==Q.front) return ERROR;//判空
Q.front++;
return OK;
}
int main(){
SqQueue Q;
int e;
float a,b;
if(InitQueue(Q)==1){
printf("队列初始化成功。\n");
printf("请输入一个十进制小数:");
scanf("%f",&a);
while(a>=1e-5){
b=a*2;
e=(int)b;
InQueue(Q,e);
a=b-e;
}
printf("该二进制数为:0.");
while(Q.front!=Q.rear){
OutQueue(Q,e);
printf("%d",e);
}
printf("\n");
}
}
11-05
2359
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交