LAB # 10 Stack ADT Implementation: Object
LAB # 10 Stack ADT Implementation: Object
LAB # 10 Stack ADT Implementation: Object
LAB # 10
Object
Implement Stack by using Stack ADT class.
Theory
Pushes an item onto the top of this stack. This has exactly the same effect as:
addElement(item)
Parameters:
item - the item to be pushed onto this stack.
Returns:
the item argument.
public E pop()
Removes the object at the top of this stack and returns that object as the value of this function.
Returns:
The object at the top of this stack (the last item of the Vector object).
Throws:
EmptyStackException - if this stack is empty.
Sample Program#1
import java.util.*;
try {
showpop(st);
} catch (EmptyStackException e) {
System.out.println("empty stack");
}
}
}
Lab Task
1. Write a program that takes 20 names as input in stack. Perform all operations on stack
using stack ADT class.
2. Convert the expression from infix to postfix using Stack ADT class.
(A+B) * (C-D)
Home Task
1. Convert and evaluate the expression from infix to postfix using Stack ADT class.
A + ( B * C - ( D / E | F ) * G ) * H