欢迎来到天天文库
浏览记录
ID:57339880
大小:13.00 KB
页数:2页
时间:2020-08-12
《顺序栈的应用(十进制转换为八进制-通过VC++调试运行).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//十进制转换为八进制.cpp:Definestheentrypointfortheconsoleapplication.#include"iostream"#include"stdlib.h"#include"stdio.h"usingnamespacestd;#defineStack_Init_Size100#defineSTACKINCREMENT10#defineoverflow-2#defineERROR0#defineOK1typedefstruct{int*base;int*top;intstacksize;}SqStack;typedefintStatus;S
2、tatusInitStack(SqStack&S){S.base=(int*)malloc(Stack_Init_Size*sizeof(int));if(!S.base)exit(overflow);S.top=S.base;S.stacksize=Stack_Init_Size;returnOK;}StatusPush(SqStack&S,inte){if(S.top-S.base>=S.stacksize){S.base=(int*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));if(!S.base)e
3、xit(overflow);S.top=S.base+S.stacksize;S.stacksize+=STACKINCREMENT;}*S.top++=e;returnOK;}StatusPop(SqStack&S,int&e){if(S.top==S.base)returnERROR;e=*--S.top;returnOK;}boolStackEmpty(SqStackS){if(S.base==S.top)return1;elsereturn0;}intmain(){intl;SqStacks;intN;InitStack(s);cout<<"请输入一个十进制数:";c
4、in>>N;while(N){Push(s,N%8);N=N/8;}cout<<"其化为八进制数为:";while(!StackEmpty(s)){Pop(s,l);cout<
此文档下载收益归作者所有