Lab 08
Lab 08
Introduction to Stacks
A stack is a data structure following the Last In, First Out (LIFO) principle, where the last
item added is the first to be removed. Common stack operations include:
3. Pop Operation:
a. Check if top is -1, indicating the stack is empty.
b. If not, return stack[top] and decrement top.
function pop():
if top < 0:
print "Stack Underflow"
else:
item = stack[top]
top = top - 1
return item
4. Peek Operation:
a. If top is -1, stack is empty.
b. Otherwise, return stack[top].
function peek():
if top < 0:
print "Stack is Empty"
else:
return stack[top]
5. isEmpty Operation:
a. Return true if top is -1, else return false.
function isEmpty():
return top < 0
4. Peek Operation:
a. If top is null, the stack is empty.
b. Otherwise, return top.data.
function peek():
if top == null:
print "Stack is Empty"
else:
return top.data
5. isEmpty Operation:
a. Return true if top is null, otherwise false.
function isEmpty():
return top == null
Tasks
1. Implement a function to check if the stack is full.
2. Modify the stack implementation to allow for dynamic resizing.
3. Create a stack implementation using a linked list.
4. Write a printStack function to display all elements in the stack from top to bottom.
5. Develop a postfix expression evaluator using a stack.
6. Write a function to reverse a string using a stack.