#include<iostream>
#include<cstdlib>
using namespace std;
template<class T>
class stack
{
private:
T *t;
int len,top;
public:
stack(int n=10)
{
t=new T[len=n];
top=0;
}
~stack(){delete []t;}
bool empty()
{
return top==0;
}
void push(int x)
{
if(top==len) exit(1);
else t[top++]=x;
}
void topp(int &x)
{
x=t[top-1];
}
void pop()
{
top--;
}
};
int main()
{
stack<int>s(100);
int n,m,x;
cin>>n>>m;
while(n!=0)
{
s.push(n%m);
n=n/m;
}
while(!s.empty())
{
s.topp(x);
s.pop();
cout<<x;
}
return 0;
}
自定义stack
最新推荐文章于 2023-10-12 20:19:51 发布