Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- public class ProductStack {
- private List<Object> list = new ArrayList<Object>();
- private int currentIndex = -1;
- public void push(Object object) {
- list.add(object);
- currentIndex++;
- }
- public Object pop(){
- Object object = list.remove(currentIndex);
- currentIndex--;
- return object;
- }
- public int count() {
- return list.size();
- }
- public Object peek(){
- return list.get(currentIndex);
- }
- public void clear(){
- list.clear();
- currentIndex = -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment