Advertisement
Samuel_Berkat_Hulu

Stack

Apr 13th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. /**
  2.  * Write a description of class Stack here.
  3.  *
  4.  * @Samuel Berkat Hulu
  5.  * @Version 5.0
  6.  */
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. public class Stack
  10. {
  11.     private List<Object> list=new ArrayList<Object>();
  12.     private int currentIndex =-1;
  13.    
  14.     public void push(Object object)
  15.     {
  16.         list.add(object);
  17.         currentIndex++;
  18.     }
  19.    
  20.     public Object pop()
  21.     {
  22.         Object object=list.remove(currentIndex);
  23.         currentIndex--;
  24.         return object;
  25.     }
  26.    
  27.     public int count()
  28.     {
  29.         return list.size();
  30.     }
  31.    
  32.     public Object peek()
  33.     {
  34.         return list.get(currentIndex);
  35.     }
  36.    
  37.     public void clear()
  38.     {
  39.         list.clear();
  40.         currentIndex=-1;
  41.     }
  42.    
  43.     public static void main(String[] args)
  44.     {
  45.        
  46.     }
  47.    
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement