收藏 分销(赏)

利用栈实现数制转换.doc

上传人:仙人****88 文档编号:9462525 上传时间:2025-03-27 格式:DOC 页数:2 大小:28.04KB
下载 相关 举报
利用栈实现数制转换.doc_第1页
第1页 / 共2页
利用栈实现数制转换.doc_第2页
第2页 / 共2页
本文档共2页,全文阅读请下载到手机保存,查看更方便
资源描述
/*利用栈实现数制转换*/ #include "stdio.h" #include "malloc.h" #define ERROR 0 #define OK 1 #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 typedef int SElemType; typedef struct stack{ SElemType *top; SElemType *bottom; int stacksize; }SqStack; int InitStack(SqStack *S) { S->bottom=(SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!S->bottom) return ERROR; S->top=S->bottom; S->stacksize=STACK_INIT_SIZE; return OK; } int Push(SqStack *S,SElemType e) { if(S->top-S->bottom>=S->stacksize-1){ S->bottom=(SElemType*)realloc(S->bottom,(S->stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S->bottom) return ERROR; S->top=S->bottom+S->stacksize; } *S->top++=e; return OK; } int Pop(SqStack *S,SElemType *e) { if(S->top==S->bottom) return ERROR; *e=*--S->top; return OK; } int StackEmpty(SqStack S) { if(S.top==S.bottom) return 1; else return 0; } void main() { SqStack myStack; int N,e; InitStack(&myStack); printf("请输入N:"); scanf("%d",&N); while(N){ Push(&myStack,N%8); N=N/8; } while(!StackEmpty(myStack)){ Pop(&myStack,&e); printf("%d",e); } printf("\n"); }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服