andari3107

Stack1

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