在这里运用了C语言中的链式存储来描述栈的存储形式及其相关运算
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
#define N 100
#define ZN 10
typedef struct{
int *base;
int *top;
int stacksize;
}sb;
sb s;
int ch(sb &s)
{
s.base=(int *)malloc(N*sizeof(int));
s.top=s.base;
s.stacksize=N;
}
int push(sb &s,int e)
{
if(s.top-s.base>=s.stacksize)
{
s.base=(int *)realloc(s.base,(s.stacksize+ZN)*sizeof(int));
s.top=s.base+s.stacksize;
s.stacksize+=ZN;
}
*s.top++=e;
}
int pop(sb &s)
{
while(s.top!=s.base)
{
s.top--;
cout<<*(s.top);
}
}
int main()
{
ch(s);
int n;
cin>>n;
while(n)
{
push(s,(n%8));
n=n/8;
}
pop(s);
return 0;
}