#include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 #define ERROR 0 #define OK 1 #define OVERFLOW -2 typedef int Status ; typedef int SElemType; typedef struct { SElemType *base; SElemType *top; int stacksize; }Sqstack; Status InitStack(Sqstack &S) {S.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!S.base) exit(OVERFLOW); S.top= S.base; S.stacksize=STACK_INIT_SIZE; return OK; } //Initstack Status GetTop(Sqstack S, SElemType &e) {if(S.base==S.top) return ERROR; e= *(S.top-1); return OK; } //GetTop Status Push(Sqstack &S, SElemType e) {if(S.top-S.base>=S.stacksize) { S.base= (SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S.base) exit(OVERFLOW); S.top=S.base+S.stacksize; S.stacksize+=STACKINCREMENT;} *S.top++=e; return OK; } // Push Status Pop(Sqstack &S,SElemType &e) {if(S.top==S.base)return ERROR; e= *--S.top; return OK; } //POP Status StackEmpty(Sqstack S){ if(S.top==S.top) return OK;else return ERROR; } //StackEmpty void main(){ Sqstack S; SElemType n,e; InitStack(S); cin>>n;cout<<endl; while(n){ Push(S,n%8); n=n/8; } while(!StackEmpty(S)){ Pop(S,e); cout<<e; } }//end
请各位高手帮我看看这个程序的结果为什么出不来