- #include<iostream.h>
- #define ten 10
- #define hundred 100
- struct sqstack
- {
- int* p;
- int top;
- int size;
- };
- void pop(sqstack &q,int &e)
- {
- e=q.p[--q.top];
- }
- void push(sqstack &q,int e)
- {
- q.p[q.top]=e;
- q.top++;
- }
- void initstack(sqstack &q)
- {
- q.top=0;
- q.size=0;
- q.p=new int[hundred];
- if(q.p)cout<<"OK"<<endl;
- }
- void main()
- {
- int a,e=0;
- sqstack q;
- initstack(q);
- cout<<"输入要转化成8进制的10进制数"<<endl;
- cin>>a;
- while(a)
- {
- push(q,a%2);
- a=a/2;
- }
- cout<<q.top<<endl;
- while(q.top)
- {
- pop(q,e);
- cout<<e;
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/201120137333.html
来源: http://www.codesnippet.cn/detail/201120137333.html