Stack and Queues Flashcards
A list ADT with the restriction that insert and delete operations can only be performed at one end called the top-of-stack (TOS)
Stack
Stack is a list ADT with the restriction that insert and delete operations can only be performed at one end called the _____________
top-of-stack (TOS)
Stack follows the __________________ policy
Last In, First Out (LIFO)
2 Main Stack Operations
push(x) and pop()
Both push and pop operations operate on ________. It is updated after every push or pop
TOS
Other stack operations
peek() - return value of TOS
isFull() - checks if stack is full
isEmpty() - checks if stack is empty
Happens when you attempt to pop an empty stack
Stack Underflow Error
Happens when you attempt to push to a full stack
Stack Overflow Error
Initial value of TOS (Static Array Solution)
int top = -1;
Push Operation Pseudocode (Static Array)
push(e):
if top < LIMIT -1
top = top + 1
stack[top] = e
else
error “Stack Overflow”
Pop Operation Pseudocode (Static Array)
pop():
if top >= 0
top = top-1
return stack[top+1]
else
error “Stack Underflow”
Linked List Solution Stack
Normal Linked list, with insertion and deletion at head (TOS)
Applications of Stack
a) Balancing open/close symbols in PLs
b) Function calls (Recursion Stack)
c) Postfix expression evaluation
A list ADT with the restriction that insert is done at one end of the list and delete is done at the other
Queue
Queue follows the ____________________ policy.
First In, First Out (FIFO)