template<typename T> class CStack {
public:
unsigned int size()
{
return StackSize;
}
T pop()
{
int top = 0;
if(StackSize != 0){
top = _Stack[StackSize-1];
T* _newstack = (T*)malloc(--StackSize * sizeof(T));
for(int i=0;i<StackSize;i++)
_newstack[i] = _Stack[i];
free(_Stack);
_Stack = _newstack;
}
return top;
}
void push(T j)
{
T* _newstack = (T*)malloc(++StackSize * sizeof(T));
if(_Stack != NULL)
{
for(int i=0;i<StackSize-1;i++)
_newstack[i] = _Stack[i];
free(_Stack);
}
_Stack = _newstack;
_Stack[StackSize-1] = j;
}
CStack()
{
StackSize = 0;
_Stack = NULL;
}
~CStack()
{
free(_Stack);
StackSize = 0;
}
private:
unsigned int StackSize;
T* _Stack;
};
Comments