Please have a look at the following code
template <typename T>
class Stack
{
public:
Stack(int number)
{
maxSize = number;
top = -1;
stackData = new T*(maxSize);
}
~Stack()
{
delete [] stackData;
}
int count()
{
}
bool isEmpty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
bool isFull()
{
if(top== (maxSize-1))
{
return true;
}
else
{
return false;
}
}
*T pop()
{
if(!isEmpty())
{
return stackData[top--]; // Remove Item From Stack
}
}
*T peek();
void push(T *pushValue)
{
if(!isFull())
{
stackData[++top] = pushValue;
}
}
private:
int maxSize;
T ** stackData;
int top;
};
In the above code, the commented line says "Removing Item from the Stack". But actually, it is not removing, it is simply providing the value which is one value behind, right? In here, I refer removing as completely destroying that particular value from the stack.
ex: In an array which contains data 1,2,3,4 I remove '2'. So now it is 1,3,4
Second, what should happen inside the "peek()" method?
Third, are there are any errors that I didn't detect?
Please help!