您的当前位置:首页正文

数值转换程序

2020-08-04 来源:独旅网
/* Note:Your choice is C IDE */ #include \"stdio.h\" #include #include //类型定义

#define STACK_INIT_SIZE 100 typedef int SElemType; typedef struct {

SElemType *top; SElemType *base; int stacksize; }SqStack;

typedef enum mybool {FALSE,TRUE} Boolean;

//初始化

void InitStack(SqStack *s) {

s->top=(SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType)); s->base=s->top;

s->stacksize=STACK_INIT_SIZE;

}

//判栈空

Boolean StackEmpty(SqStack *s) {

if(s->base==s->top) return(TRUE); else return(FALSE); } //进栈

Boolean Push(SqStack *s,SElemType e) {

if((s->top-s->base)>=s->stacksize) return(FALSE); *(s->top)=e; s->top++; return(TRUE); } //退栈

Boolean Pop(SqStack *s,SElemType *e) {

if(s->base==s->top)return(FALSE); s->top--;*e=*(s->top); return(TRUE); } //主函数 void main() {

SqStack s; SElemType n,e; InitStack(&s); scanf(\"%d\",&n); while(n) { while(n) {

if(Push(&s,n%8))printf(\" \");n=n/8; }

printf(\"\\n\");

while(!StackEmpty(&s)) {

if(Pop(&s,&e))printf(\" \"); printf(\"%d\",e); }printf(\"\\n\"); scanf(\"%d\",&n);} }

因篇幅问题不能全部显示,请点此查看更多更全内容