Advertisement
Aldin-SXR

dequeue()

Mar 5th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. /* Removes an item from the front of the queue, and returns its data */
  2. public Item dequeue() {
  3.     Item item = q[head];                            // 1
  4.     q[head] = null;                                 // 2
  5.     head = (head + 1) % q.length;                   // 3
  6.        
  7.     if (length > 0 && length == q.length / 4) {     // 4
  8.         resize(q.length / 2);                       // 4
  9.     }                                               // 4
  10.        
  11.     length--;                                       // 5
  12.     return item;                                    // 6
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement