0% found this document useful (0 votes)
49 views1 page

How A Stack Works

weerertdfdf

Uploaded by

zaheer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views1 page

How A Stack Works

weerertdfdf

Uploaded by

zaheer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

How a Stack Works

The operations work as follows:

1. A pointer called TOP is used to keep track of the top element in the
stack.
2. When initializing the stack, we set its value to -1 so that we can check if
the stack is empty by comparing TOP == -1.
3. On pushing an element, we increase the value of TOP and place the new
element in the position pointed to by TOP.
4. On popping an element, we return the element pointed to by TOP and
reduce its value.
5. Before pushing, we check if the stack is already full
6. Before popping, we check if the stack is already empty

Stack Operations

You might also like