Advertisement
korobushk

q

May 23rd, 2021
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. // "static void main" must be defined in a public class.
  2.  
  3. class MyQueue {
  4.     // store elements
  5.     private List<Integer> data;        
  6.     // a pointer to indicate the start position
  7.     private int p_start;            
  8.     public MyQueue() {
  9.         data = new ArrayList<Integer>();
  10.         p_start = 0;
  11.     }
  12.     /** Insert an element into the queue. Return true if the operation is successful. */
  13.     public boolean enQueue(int x) {
  14.         data.add(x);
  15.         return true;
  16.     };    
  17.     /** Delete an element from the queue. Return true if the operation is successful. */
  18.     public boolean deQueue() {
  19.         if (isEmpty() == true) {
  20.             return false;
  21.         }
  22.         p_start++;
  23.         return true;
  24.     }
  25.     /** Get the front item from the queue. */
  26.     public int Front() {
  27.         return data.get(p_start);
  28.     }
  29.     /** Checks whether the queue is empty or not. */
  30.     public boolean isEmpty() {
  31.         return p_start >= data.size();
  32.     }    
  33. };
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement