欢迎来到天天文库
浏览记录
ID:59298193
大小:68.00 KB
页数:2页
时间:2020-09-06
《数据结构中用栈把10进制转换为2进制.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include"stdio.h"#include"stdlib.h"#defineSTACK_INIT_SIZE100;#defineSTACKINCREMENT10;typedefintSElemType;typedefintElemType;typedefstruct{int*base;int*top;intstacksize;}SqStack;voidInitStack(SqStack*S){S->base=(SElemType*)malloc(100);S->top=S->base;S->stacksi
2、ze=100;}voidpush(SqStack*S,inte){S->base=(SElemType*)realloc(S->base,(S->stacksize+10));*S->top++=e;}voidpop(SqStack*S,SElemType*e){if(S->top==S->base)exit(0);*e=*--S->top;}voidconversion(intn){inta,*e=&a;SqStackw,*S=&w;InitStack(S);while(n){push(S,n%2);n=n/2
3、;}while(S->top!=S->base){pop(S,e);printf("%d",*e);}}main(){intm;scanf("%d",&m);conversion(m);}
此文档下载收益归作者所有