1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #define MaxSize 50 typedef struct{ Elemtype data[MaxSize]; int top; }SqStack; bool Push(SqStack &S,Elemtype x){ if(S.top==MaxSize-1) return false; S.data[++S.top]=x; return true; }
bool Pop(SqStack &S,Elemtype &x){ if(S.top==-1) return false; x=S.data[S.top--]; return true; }
SqStack s; int N; ElemType e; if(InitStack(S))printf("\n 初始化栈成功!\n"); printf("\n请输入想要转换的非负十进制整数(以回车键结束):\n"); scanf("%d",&N); while(N){ Push(S,N%8); N/=8; } printf("\n 该数对应的八进制数为:\n"); while(!StackEmpty(S)){ Pop(S,&e); printf("%d",e); }
|