Guest User

Untitled

a guest
Apr 12th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class ProductStack {
  5.    
  6.     private List<Object> list = new ArrayList<Object>();
  7.     private int currentIndex = -1;
  8.  
  9.     public void push(Object object) {
  10.         list.add(object);
  11.         currentIndex++;
  12.     }
  13.  
  14.     public Object pop(){
  15.         Object object = list.remove(currentIndex);
  16.         currentIndex--;
  17.         return object;
  18.     }
  19.  
  20.     public int count() {
  21.         return list.size();
  22.     }
  23.  
  24.     public Object peek(){
  25.         return list.get(currentIndex);
  26.     }
  27.  
  28.     public void clear(){
  29.         list.clear();
  30.         currentIndex = -1;
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment