Im trying to learn about stacks as an abstract data type creating my own. my code complies but im getting a logical error when displayed I keep getting a 12 or some random number im thinking there is a problem with my printStack function with displaying the copy of the stack from the for loop
Have you learned of arrays? You must have, because you're using a class.
Anyway, it's conventional to use an array to hold the elements. You seem to be doing some weird shift thing. You're not storing bits your storing ints.
void push(newItem)// item n is pushed onto stack, throw exception on full stack.
{
if (isFull())
{
throw"The Stack Is Full";
}
newItem = newItem & 0x0F;
items = items << 4;
items = items | newItem;
count++;
}
void pop() // removes top item from stack, throw exception on empty stack.
{
if (isEmpty())
{
throw"The Stack Is Empty";
}
else items = items >> 4;
count--;}
but now im getting a logic error with my pop function when I push 321 on to the stack and I pop it off 3 times it just says 1 was popped off instead of popped number 1 popped number 2 popped number 3